← All procedures

shell.stream

Run a command and stream each output line as it arrives

CLI
Package
@procedures/shell · README
Path
["shell","stream"]
CLI
mark shell stream --command <string>
As data
{"$proc":["shell","stream"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/shell"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["shell","stream"], { command: "<command>" });
console.log(JSON.stringify(result));

From the command line

$ mark shell stream --command <string>

As data, in a program

{ "$proc": ["shell", "stream"], "input": { "command": "<command>" } }

Input

FieldTypeRequiredDefaultDescription
commandstringyesThe program to start (no shell: arguments go in args)
argsstring[]no[]The arguments of the program
cwdstringnoWorking directory
envobjectnoEnvironment variables (added to the environment of the host)
timeoutnumbernoTimeout in milliseconds. At the timeout, the program and its children are killed.

Output

The schema does not list fields (object | object).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "command": {
        "type": "string",
        "description": "The program to start (no shell: arguments go in args)"
      },
      "args": {
        "default": [],
        "description": "The arguments of the program",
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "cwd": {
        "description": "Working directory",
        "type": "string"
      },
      "env": {
        "description": "Environment variables (added to the environment of the host)",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "type": "string"
        }
      },
      "timeout": {
        "description": "Timeout in milliseconds. At the timeout, the program and its children are killed.",
        "type": "number"
      }
    },
    "required": [
      "command"
    ]
  },
  "output": {
    "anyOf": [
      {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "stdout",
              "stderr"
            ],
            "description": "The stream of the line"
          },
          "line": {
            "type": "string",
            "description": "One line of output, without its line end"
          }
        },
        "required": [
          "type",
          "line"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "const": "exit",
            "description": "The end of the stream (the last item)"
          },
          "exitCode": {
            "type": "number",
            "description": "The exit code (-1 when a signal ended the program)"
          },
          "duration": {
            "type": "number",
            "description": "The time of the command, in milliseconds"
          },
          "signal": {
            "description": "The signal that ended the program",
            "type": "string"
          }
        },
        "required": [
          "type",
          "exitCode",
          "duration"
        ],
        "additionalProperties": {}
      }
    ]
  }
}