I'm writing a quick Rails app and was wondering how I can validate the success an exec'd command. The two commands I'm running are and SVN update, and a cp from one directory to another.
If you use the Kernel.system() method it will return a boolean indicating the success of the command.
result = system("cp -r dir1 dir2")
if(result)
#do the next thing
else
# handle the error
There is a good comparison of different ruby system commands here.
How are you executing the external commands? The Ruby system()
function returns true
or false
depending on whether the command was successful. Additionally, $?
contains an error status.
exec
'd command because exec
replaces the current program with the exec
'd command, so the command would never return to Ruby for validation.$?
predefined variable will give you the return code of the last command to be executed by system()
or the backtick operator.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With