Skip to main content

module ShellExec

rascal-0.28.2

Usage

import util::ShellExec;

Synopsis

Execute and manage external processes.

function createProcess

Synopsis

Start a new external process.

PID createProcess(str processCommand, loc workingDir=|cwd:///|, list[str] args = [], map[str,str] envVars = ())

PID createProcess(loc processCommand, loc workingDir=|cwd:///|, list[value] args = [], map[str, value] envVars = ())

function exec

str exec(str processCommand, loc workingDir=|cwd:///|, list[str] args = [], map[str, str] env = ())

str exec(loc processCommand, loc workingDir=|cwd:///|, list[value] args = [], map[str, value] env = ())

function execWithCode

tuple[str output, int exitCode] execWithCode(str processCommand, loc workingDir=|cwd:///|, list[str] args = [], map[str, str] env = ())

tuple[str output, int exitCode] execWithCode(loc processCommand, loc workingDir=|cwd:///|, list[value] args = [], map[str, value] env = ())

function killProcess

Synopsis

Kill a running process, or a zombie process (a process which is not alive yet not killed)

int killProcess(PID processId, bool force=false)

function isAlive

Synopsis

Check whether a process is still alive

bool isAlive(PID processId)

function isZombie

Synopsis

Check whether a process is still registered but not actually running anymore. A zombie process may be cleaned up using killProcess.

bool isZombie(PID processId)

function exitCode

Synopsis

Waits for the process to exit and then returns its return code. This is a blocking operation.

int exitCode(PID processId)

function readFrom

Synopsis

Read from an existing process's output stream. This is non-blocking.

str readFrom(PID processId)

function readWithWait

Synopsis

Read from an existing process's output stream with a given wait timeout. Some processes are a little slower in producing output. The wait is used to give the process some extra time in producing output. This is non-blocking apart from the waiting.

str readWithWait(PID processId, int wait)

function readFromErr

Synopsis

Read from an existing process's error output stream. This is non-blocking.

str readFromErr(PID processId)

function readLineFromErr

Synopsis

Read from an existing process's error output stream. This blocks until a full line is read and waits for one second maximally for this line to appear.

str readLineFromErr(PID processId, int wait=200, int maxTries=5)

function readEntireStream

Synopsis

Read the entire stream from an existing process's output stream. This is blocking.

str readEntireStream(PID processId)

function readEntireErrStream

Synopsis

Read the entire error stream from an existing process's output stream. This is blocking.

str readEntireErrStream(PID processId)

function writeTo

Synopsis

Write to an existing process's input stream.

void writeTo(PID processId, str msg)

alias PID

int

Synopsis

Process Identifiers (PID).

Description

A PID is returned by Create Process and is required for any further interaction with the created process.