StartProcess

StartProcess["executable"]
executes an external program, yielding a ProcessObject to represent the resulting subprocess.

StartProcess[{"executable",arg1,arg2,}]
executes an external program, passing it the specified arguments .

更多信息更多信息

  • StartProcess returns a ProcessObject if the process it specifies can be started; otherwise, it returns $Failed.
  • StartProcess can be used to interact with processes while they are running or to run "background tasks" without blocking the Wolfram Engine.
  • StartProcess returns immediately and does not wait for the started process to complete. Use RunProcess to wait for a process to complete.
  • In , the are converted to strings using ToString.
  • The Wolfram Engine can communicate with a subprocess represented by a ProcessObject with functions like WriteLine, WriteString, BinaryWrite, ReadLine, ReadString, and BinaryRead.
  • The standard input, output, and error streams can be represented using ProcessConnection.
  • Information about the subprocess can be queried using ProcessStatus and ProcessInformation.
  • The following options can be given:
  • ProcessDirectoryInheritedinitial working directory
    ProcessEnvironmentInheritedenvironment variables to give the subprocess
  • 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 are of the form "name"->value, they will be converted into the form . If name is a single character, only one dash will be used.

范例范例打开所有单元关闭所有单元

基本范例  (1)基本范例  (1)

Start the system shell process:

In[1]:=
Click for copyable input
Out[1]=

Write a command into the system shell process:

In[2]:=
Click for copyable input

Read the command output:

In[3]:=
Click for copyable input
Out[3]=

Check whether the process is running or not:

In[4]:=
Click for copyable input
Out[4]=

Write an exit command into the shell process:

In[5]:=
Click for copyable input

Verify the program has actually finished:

In[6]:=
Click for copyable input
Out[6]=
2014年引入
(10.0)