← All procedures

shell.exec

Execute command string via shell

CLI
Package
@procedures/shell · README
Path
["shell","exec"]
CLI
mark shell exec --command <string>
As data
{"$proc":["shell","exec"],"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","exec"], { command: "<command>" });
console.log(JSON.stringify(result));

From the command line

$ mark shell exec --command <string>

As data, in a program

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

Input

FieldTypeRequiredDefaultDescription
commandstringyesFull command string to execute via shell
cwdstringnoWorking directory
envobjectnoEnvironment variables
timeoutnumbernoTimeout in milliseconds. At the timeout, the shell and the programs that it started are killed.
shellboolean | stringnotrueShell to use: a path, or `true` for the system shell (`cmd.exe` or `/bin/sh`). `false` is the same as `true`.
maxBuffernumbernoThe most bytes kept of each output stream (default: 64 MiB). The procedure drops the rest.
stdinstringnoText to write to stdin. Without it, stdin is empty.

Output

FieldTypeRequiredDefaultDescription
exitCodenumberyesThe exit code (0 is success, -1 when a signal ended the program)
stdoutstringyesThe standard output
stderrstringyesThe standard error
successbooleanyesTrue when the exit code is 0
durationnumberyesThe time of the command, in milliseconds
signalstringnoThe signal that ended the program (for example at the timeout)
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "command": {
        "type": "string",
        "description": "Full command string to execute via shell"
      },
      "cwd": {
        "description": "Working directory",
        "type": "string"
      },
      "env": {
        "description": "Environment variables",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "type": "string"
        }
      },
      "timeout": {
        "description": "Timeout in milliseconds. At the timeout, the shell and the programs that it started are killed.",
        "type": "number"
      },
      "shell": {
        "default": true,
        "description": "Shell to use: a path, or `true` for the system shell (`cmd.exe` or `/bin/sh`). `false` is the same as `true`.",
        "type": [
          "boolean",
          "string"
        ]
      },
      "maxBuffer": {
        "description": "The most bytes kept of each output stream (default: 64 MiB). The procedure drops the rest.",
        "type": "number"
      },
      "stdin": {
        "description": "Text to write to stdin. Without it, stdin is empty.",
        "type": "string"
      }
    },
    "required": [
      "command"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "exitCode": {
        "type": "number",
        "description": "The exit code (0 is success, -1 when a signal ended the program)"
      },
      "stdout": {
        "type": "string",
        "description": "The standard output"
      },
      "stderr": {
        "type": "string",
        "description": "The standard error"
      },
      "success": {
        "type": "boolean",
        "description": "True when the exit code is 0"
      },
      "duration": {
        "type": "number",
        "description": "The time of the command, in milliseconds"
      },
      "signal": {
        "description": "The signal that ended the program (for example at the timeout)",
        "type": "string"
      }
    },
    "required": [
      "exitCode",
      "stdout",
      "stderr",
      "success",
      "duration"
    ],
    "additionalProperties": {}
  }
}