({{, (RefLink[StartProcess, paclet:ref/StartProcess])["executable"] 
executes an external program, yielding a (RefLink[ProcessObject, paclet:ref/ProcessObject]) to represent the resulting subprocess.}, {, (RefLink[StartProcess, paclet:ref/StartProcess])[{"executable",(Subscript[arg, 1]),(Subscript[arg, 2]),…}]
executes an external program, passing it the specified arguments (Subscript[arg, i]).}})

OpenersNotesSection(Spacer1)Details

(RefLink[StartProcess, paclet:ref/StartProcess]) returns a (RefLink[ProcessObject, paclet:ref/ProcessObject]) if the process it specifies can be started; otherwise, it returns (RefLink[$Failed, paclet:ref/$Failed]).

(RefLink[StartProcess, paclet:ref/StartProcess]) can be used to interact with processes while they are running or to run "background tasks" without blocking the Wolfram Engine.

(RefLink[StartProcess, paclet:ref/StartProcess]) returns immediately and does not wait for the started process to complete. Use (RefLink[RunProcess, paclet:ref/RunProcess]) to wait for a process to complete.

In (RefLink[StartProcess, paclet:ref/StartProcess])[{"executable",(Subscript[arg, 1]),(Subscript[arg, 2]),…}], the (Subscript[arg, i]) are converted to strings using (RefLink[ToString, paclet:ref/ToString]).

The Wolfram Engine can communicate with a subprocess represented by a (RefLink[ProcessObject, paclet:ref/ProcessObject]) with functions like (RefLink[WriteLine, paclet:ref/WriteLine]), (RefLink[WriteString, paclet:ref/WriteString]), (RefLink[BinaryWrite, paclet:ref/BinaryWrite]), (RefLink[ReadLine, paclet:ref/ReadLine]), (RefLink[ReadString, paclet:ref/ReadString]), and (RefLink[BinaryRead, paclet:ref/BinaryRead]).

The standard input, output, and error streams can be represented using (RefLink[ProcessConnection, paclet:ref/ProcessConnection]).

Information about the subprocess can be queried using (RefLink[ProcessStatus, paclet:ref/ProcessStatus]) and (RefLink[ProcessInformation, paclet:ref/ProcessInformation]).

The following options can be given:

By default, the subprocess will inherit its process directory and environment variables from the Wolfram Engine.

If the Wolfram Engine is terminated, the subprocess will be forced to close.

If any of the arguments (Subscript[arg, i]) are of the form "name"->value, they will be converted into the form "--name=value". If name is a single character, only one dash will be used.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Start the system shell process:

process=StartProcess[$SystemShell]

Write a command into the system shell process:

WriteLine[process,"echo example line"];

Read the command output:

ReadString[process,EndOfBuffer]

Check whether the process is running or not:

ProcessStatus[process]

Write an exit command into the shell process:

WriteLine[process,"exit"];

Verify the program has actually finished:

ProcessStatus[process]

OpenersExampleSection2(Spacer1)Possible Issues  (4)

The right way to call (RefLink[StartProcess, paclet:ref/StartProcess]) for a program plus its arguments is using a list:

StartProcess[{$SystemShell,"-c","echo example line"}]

Calling (RefLink[StartProcess, paclet:ref/StartProcess]) with the command and arguments in a single string is not allowed:

StartProcess[StringJoin[{$SystemShell," -c \"echo example line\""}]]

Also, calling (RefLink[StartProcess, paclet:ref/StartProcess]) with the program arguments as arguments for (RefLink[StartProcess, paclet:ref/StartProcess]) is not allowed:

StartProcess[$SystemShell,"-c","echo example line"]

Special symbols like ~ and * are not converted using shell expansion, because (RefLink[StartProcess, paclet:ref/StartProcess]) skips the shell:

StartProcess[{"diff","~/file1","~/file2"}]

Shell commands like dir, echo cannot be called directly on Windows because they are not binaries (however, they work on Unix systems because they are Unix binaries):

StartProcess[{"echo","this line only works on Unix systems like MacOS and Linux"}]

Some commands might need to be called using absolute paths:

StartProcess[{"/bin/echo","example"}]

OpenersExampleSection3(Spacer1)Interactive Examples  (1)

Create an interactive console in the Wolfram Language. To test this example, first evaluate the cells. Then type any valid shell command in the input box and click the Go button:

command="";
process=StartProcess[$SystemShell];
Pause[.1];
processString=ReadString[process,EndOfBuffer];

Column[{
Pane[Dynamic[processString],ImageSize->{800,400},Scrollbars->True,ScrollPosition->{-1,-1}],
InputField[Dynamic[command],String],
Button["Go!",WriteLine[process,command];
Pause[.1];
processString=processString<>ReadString[process,EndOfBuffer];
]}]

OpenersExampleSection4(Spacer1)Neat Examples  (1)

Start a new WolframKernel process for parallel computation:

path=FileNames["WolframKernel"|"WolframKernel.exe",$InstallationDirectory,3]

process=StartProcess[path]

Make the kernel process do a long computation and quit:

Do[WriteLine[process,"42^42"],{5}]

WriteLine[process,"Quit[]"];

Read the process output whenever it finishes:

string=ReadString[process]

Read any messages sent to the error stream:

ReadString[ProcessConnection[process,"StandardError"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[StartExternalSession, paclet:ref/StartExternalSession])  ▪  (RefLink[RunProcess, paclet:ref/RunProcess])  ▪  (RefLink[KillProcess, paclet:ref/KillProcess])  ▪  (RefLink[ProcessConnection, paclet:ref/ProcessConnection])  ▪  (RefLink[LaunchKernels, paclet:ref/LaunchKernels])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[External Language Interfaces, paclet:guide/ExternalLanguageInterfaces])}, {▪(RefLinkPlain[Background & Scheduled Tasks, paclet:guide/BackgroundAndScheduledTasks])}, {▪(RefLinkPlain[Direct Control of External Processes, paclet:guide/DirectControlOfExternalProcesses])}, {▪(RefLinkPlain[Calling External Programs, paclet:guide/CallingExternalPrograms])}})}})