Skip to content
CShift0.32

Process

Struct · namespace System

struct Process

Runs other programs and reads environment variables (static functions).

int code = Process.Run("clang -c a.c -o a.o");
var text = Process.RunCapture("clang --version"); // the text the program writes to stdout
Name Description
Run Runs a command line through the system shell (sh or cmd.exe) and waits for it.
IsWindows True on Windows.
IsMacOS True on macOS: the file that names the version of the system exists (/System/Library/CoreServices/SystemVersion.plist).
RunCapture Runs a command line through the system shell and returns everything the program writes to stdout.
GetEnv The value of the environment variable name.
static int Run(StringSlice command)

Runs a command line through the system shell (sh or cmd.exe) and waits for it. What the program wrote before is written out first, so that the output of the command comes after it.

Returns the exit code of the program, or -1 if it could not be started.

static bool IsWindows()

True on Windows. The environment variable OS is not always passed on (e.g. by an MSYS2 login shell), so the system’s cmd.exe is looked for as well.

static bool IsMacOS()

True on macOS: the file that names the version of the system exists (/System/Library/CoreServices/SystemVersion.plist). False on Windows, Linux, WebAssembly and AmigaOS.

Since 0.32

static Optional<string> RunCapture(StringSlice command)

Runs a command line through the system shell and returns everything the program writes to stdout.

Returns nothing (null) if the program could not be started.

static Optional<string> GetEnv(StringSlice name)

The value of the environment variable name.

Returns nothing (null) if it is not set.