ignorestatus
ignorestatus(command)
Mark a command object so that running it will not throw an error if the result code is non-zero.
Examples
-
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. -
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 withignorestatus
and then executed usingrun
. The result code is ignored, and the command is executed successfully. - 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"
andgrep "World"
) is created and then marked withignorestatus
. 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.