I know it should be streightforward, but I’m not finding the docs
anywhere…
How does one go about rescuing a failed shell command? like in the
instance it fails, or the command isn’t found?
Thanks,
Kyle
I know it should be streightforward, but I’m not finding the docs
anywhere…
How does one go about rescuing a failed shell command? like in the
instance it fails, or the command isn’t found?
Thanks,
Kyle
On Wed, Dec 3, 2008 at 6:02 PM, Kyle S. [email protected]
wrote:
I know it should be streightforward, but I’m not finding the docs anywhere…
How does one go about rescuing a failed shell command? like in the
instance it fails, or the command isn’t found?
According to some experiments in IRB, the failed shell command won’t
raise an exception; it will leave a non-zero exit code in the $?
special variable. You’ll need to check the value of $? and take
action accordingly.
–
Avdi
Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com
On Wed, Dec 3, 2008 at 9:28 PM, Avdi G. [email protected] wrote:
According to some experiments in IRB, the failed shell command won’t
raise an exception; it will leave a non-zero exit code in the $?
special variable. You’ll need to check the value of $? and take
action accordingly.–
Avdi
Advi, the problem is I’ve got a script failing on a “command not
found”, and not continuing onward. I see no amount of fiddling that
can help that.
From: Kyle S. [mailto:[email protected]]
what is kernel#system?
Executes cmd in a subshell, returning true if the command was
found and ran successfully, false otherwise. An error status is
available in $?. The arguments are processed in the same way as
for Kernel::exec.
system("echo *")
system("echo", "*")
basically, you’ll just have to ask it, like
rescue_command_here unless system(my_shell_command)
lastly, you’ll have to test it (because i just type this answers on my
inbox w/o testing
On Thu, Dec 4, 2008 at 8:58 AM, Kyle S. [email protected]
wrote:
Advi, the problem is I’ve got a script failing on a “command not
found”, and not continuing onward. I see no amount of fiddling that
can help that.
You may need to use IO.popen() instead, then.
–
Avdi
Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com
On Thu, Dec 4, 2008 at 8:58 AM, Kyle S. [email protected]
wrote:
Advi, the problem is I’ve got a script failing on a “command not
found”, and not continuing onward. I see no amount of fiddling that
can help that.
Just tried it… it works fine for me, outputs the “command not found”
message on stderr but keeps right on going… what platform are you
on?
–
Avdi
Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com
On Thu, Dec 4, 2008 at 10:45 AM, Avdi G. [email protected] wrote:
Just tried it… it works fine for me, outputs the “command not found”
message on stderr but keeps right on going… what platform are you
on?–
Avdi
Linux, CentOS/RedHat. Depending on the box it’ll be anywhere from
2.1AS all the way through 5.2, so the code is actually run on a rather
wide variety.
–Kyle
On Wed, Dec 3, 2008 at 9:42 PM, Peña, Botp [email protected]
wrote:
Executes cmd in a subshell, returning true if the command was
basically, you’ll just have to ask it, like
rescue_command_here unless system(my_shell_command)
lastly, you’ll have to test it (because i just type this answers on my inbox w/o testing
Would work, but I can’t use system because I need to capture and
process the output of the shell commands.
Thanks though.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs