Run a command object, constructed with backticks. Throws an error if anything goes wrong, including the process exiting with a non-zero status.


julia> run(`echo hello`)
julia> run(`echo "hello"`)
julia> run(`echo (hello)`)
julia> run(`ls`)

Here are some common examples of its use:

  1. Run a command and display output:

    julia> run(`echo "Hello, Julia!"`)
    Hello, Julia!

    This example runs the echo command with the argument "Hello, Julia!" and displays the output.

  2. Execute a system command:

    julia> run(`git status`)
    On branch master
    Your branch is up to date with 'origin/master'.
    nothing to commit, working tree clean

    In this example, the git status command is executed, and the output is displayed.

  3. Throw an error if command fails:
    julia> run(`false`)
    ERROR: failed process: Process(`false`, ProcessExited(1)) [1]

    When a command fails, such as running the false command, an error is thrown.

Common mistake example:

julia> run("echo 'Hello, Julia!'")
ERROR: MethodError: no method matching run(::String)

In this example, the run function is incorrectly used with a string argument instead of a command object constructed with backticks. It's important to construct the command with backticks (`) to create a command object before passing it torun`.

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: