Run a command object asynchronously, returning the resulting Process object.


  1. Run a command asynchronously:

    julia> cmd = run(`ls`)
    julia> p = spawn(cmd)
    Process(`ls`, ProcessRunning)

    This example creates a command object using the backticks syntax and runs it asynchronously using spawn. The resulting Process object is returned.

  2. Capture the output of a command:

    julia> cmd = run(`echo "Hello, Julia!"`)
    julia> p = spawn(cmd)
    Process(`echo "Hello, Julia!"`, ProcessRunning)

    It runs a command that prints a message and captures the output by using spawn.

  3. Check the status of a spawned process:
    julia> cmd = run(`sleep 5`)
    julia> p = spawn(cmd)
    Process(`sleep 5`, ProcessRunning)
    julia> isrunning(p)

    This example demonstrates how to check if a Process object created by spawn is 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.

*Required Field

Checking you are not a robot: