Mark a command object so that it will be run in a new process group, allowing it to outlive the julia process, and not have Ctrl-C interrupts passed to it.


  1. Detach a command in a new process group:

    julia> detach(`sleep 10`)
    Command(`sleep 10`, ProcessExited(0))

    This example detaches the command sleep 10 in a new process group, allowing it to run independently of the Julia process.

  2. Detach a command with arguments:

    julia> detach(`echo "Hello, world!"`)
    Command(`echo "Hello, world!"`, ProcessExited(0))

    It detaches the command echo "Hello, world!" with arguments and executes it in a separate process group.

  3. Detach a command and handle the process exit status:
    julia> result = detach(`ls non-existent-file`)
    Command(`ls non-existent-file`, ProcessExited(2))
    julia> result.status

    This example detaches the command ls non-existent-file and captures the process exit status in the result variable.

Common mistake example:

julia> detach(`non-existent-command`)
ERROR: could not spawn `non-existent-command`: no such file or directory (ENOENT)

In this example, the command provided does not exist, resulting in an error. Make sure to provide a valid command that can be executed in a separate process group using detach.

See Also

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: