Function Repository Resource:

SystemShellRun

Source Notebook

Run a command on the current system shell

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["SystemShellRun"]["command"]

runs the specified command in the current $SystemShell, returning information on the outcome.

ResourceFunction["SystemShellRun"][command,"prop"]

returns only the specified property.

Details and Options

ResourceFunction["SystemShellRun"] blocks until the process it starts has finished.
Typical possible properties to return include:
"ExitCode"the exit code for the process
"StandardOutput"data sent to standard output,as a string
"StandardError"data sent to standard error,as a string
Allan association of all properties (default)
ResourceFunction["SystemShellRun"] has the following options:
ProcessDirectoryInheritedinitial working directory
ProcessEnvironmentInheritedenvironment variables to supply
By default, the subprocess will inherit its process directory and environment variables from the Wolfram Engine.

Examples

Basic Examples (4) 

Run an external command in the current $SystemShell:

In[1]:=
ResourceFunction["SystemShellRun"]["echo hello world"]
Out[1]=

Run a command and get back only what it writes to the standard output channel:

In[2]:=
ResourceFunction[
 "SystemShellRun"]["echo hello world", "StandardOutput"]
Out[2]=

Run a command and get back only its exit code:

In[3]:=
ResourceFunction["SystemShellRun"]["fail", "ExitCode"]
Out[3]=
In[4]:=
ResourceFunction["SystemShellRun"]["echo hello world", "ExitCode"]
Out[4]=

Get multiple properties:

In[5]:=
ResourceFunction[
 "SystemShellRun"]["fail", {"ExitCode", "StandardError"}]
Out[5]=

Properties and Relations (1) 

SystemShellRun is a cross-platform shortcut for using RunProcess with $SystemShell:

In[6]:=
ResourceFunction["SystemShellRun"]["echo hello world"]
Out[6]=
In[7]:=
RunProcess[{$SystemShell, If[StringContainsQ[$OperatingSystem, "Windows"], "/c", "-c"], "echo", "hello", "world"}]
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 10 January 2019

Related Resources

License Information