spawn
spawn(command)
Run a command object asynchronously, returning the resulting Process object.
Examples
-
Run a command asynchronously:
julia> cmd = run(`ls`) julia> p = spawn(cmd) Process(`[4mls[24m`, ProcessRunning)This example creates a command object using the backticks syntax and runs it asynchronously using
spawn. The resultingProcessobject is returned. -
Capture the output of a command:
julia> cmd = run(`echo "Hello, Julia!"`) julia> p = spawn(cmd) Process(`[4mecho[24m [4m"Hello, Julia!"[24m`, ProcessRunning)It runs a command that prints a message and captures the output by using
spawn. - Check the status of a spawned process:
julia> cmd = run(`sleep 5`) julia> p = spawn(cmd) Process(`[4msleep[24m [4m5[24m`, ProcessRunning) julia> isrunning(p) trueThis example demonstrates how to check if a
Processobject created byspawnis still running or not.
Common mistake example:
julia> cmd = run("ls")
julia> p = spawn(cmd)
ERROR: UndefVarError: spawn not defined
In this example, the spawn function is not defined because the Cmd object is created using a string instead of the backticks syntax. To use spawn, make sure to construct the command object correctly using backticks.
See Also
addprocs, atexit, cd, clipboard, EnvHash, exit, getpid, peakflops, ProcessExitedException, process_exited, process_running, procs, quit, readandwrite, redirect_stdout, rmprocs, run, setenv, spawn, withenv,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.