ignorestatus

ignorestatus(command)

Mark a command object so that running it will not throw an error if the result code is non-zero.

Examples

  1. Ignore status of a command:

    julia> cmd = `ls non_existent_directory`;
    julia> ignorestatus(cmd)
    Cmd(`ls non_existent_directory`, 0x0000000000000001, :inherit)

    This example marks the command ls non_existent_directory so that running it will not throw an error even if the result code is non-zero.

  2. Execute ignored command:

    julia> cmd = `echo "Hello, World!"`;
    julia> ignored_cmd = ignorestatus(cmd);
    julia> run(ignored_cmd)
    Hello, World!

    Here, the command echo "Hello, World!" is marked with ignorestatus and then executed using run. The result code is ignored, and the command is executed successfully.

  3. Ignore status of a piped command:
    julia> cmd1 = `echo "Hello"`;
    julia> cmd2 = `grep "World"`;
    julia> pipe_cmd = pipeline(cmd1, cmd2);
    julia> ignorestatus(pipe_cmd)
    Pipeline(`echo "Hello" | grep "World"`, 0x0000000000000001, :inherit)

    In this example, a pipeline of two commands (echo "Hello" and grep "World") is created and then marked with ignorestatus. The pipeline is now set to ignore the status of each command.

Common mistake example:

julia> cmd = `rm non_existent_file`;
julia> ignored_cmd = ignorestatus(cmd);
julia> run(ignored_cmd)
ERROR: failed process: Process(`rm non_existent_file`, ProcessExited(1)) [1]
Stacktrace:
...

In this example, the rm command is marked with ignorestatus, but when executing it with run, the error is still thrown because the file doesn't exist. ignorestatus only ignores the status code and not other errors that may occur during command execution.

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
Details

Checking you are not a robot: