success
success(command)
Run a command object, constructed with backticks, and tell whether it was successful (exited with a code of 0). An exception is raised if the process cannot be started.
Examples
julia> success(`ls`)
true
julia> success(`rm non_existing_file.txt`)
false
-
Check if a command was successful:
julia> success(`ls`) true
This example runs the
ls
command and checks if it was successful. If the command exits with a code of 0,success
returnstrue
. - Handle unsuccessful commands:
julia> success(`rm non_existing_file.txt`) false
It checks if a command to remove a non-existing file was successful. Since the file doesn't exist, the command will fail and
success
returnsfalse
.
Common mistake example:
julia> success(`invalid_command`)
ERROR: could not spawn `invalid_command`: no such file or directory (ENOENT)
In this example, an invalid command is provided, which leads to an error. Make sure to provide a valid command that can be executed to avoid such errors.
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.