Rescuing a failed %x[] call?

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

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.

···

On Wed, Dec 3, 2008 at 6:02 PM, Kyle Schmitt <kyleaschmitt@gmail.com> 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?

--
Avdi

Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

# I know it should be streightforward, but I'm not finding the
# docs anywhere...

what is kernel#system?

botp@botp-desktop:~$ qri kernel#system
------------------------------------------------ Kernel#system
     system(cmd [, arg, ...]) => true or false

···

From: Kyle Schmitt [mailto:kyleaschmitt@gmail.com]
-------------------------------------------------
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", "*")

# How does one go about rescuing a failed shell command?
# like in the instance it fails, or the command isn't found?

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 :slight_smile:

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.

···

On Wed, Dec 3, 2008 at 9:28 PM, Avdi Grimm <avdi@avdi.org> 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

Would work, but I can't use system because I need to capture and
process the output of the shell commands.

Thanks though.

···

On Wed, Dec 3, 2008 at 9:42 PM, Peña, Botp <botp@delmonte-phil.com> wrote:

From: Kyle Schmitt [mailto:kyleaschmitt@gmail.com]
# I know it should be streightforward, but I'm not finding the
# docs anywhere...

what is kernel#system?

botp@botp-desktop:~$ qri kernel#system
------------------------------------------------ Kernel#system
    system(cmd [, arg, ...]) => true or false
-------------------------------------------------
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", "*")

# How does one go about rescuing a failed shell command?
# like in the instance it fails, or the command isn't found?

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 :slight_smile:

You may need to use IO.popen() instead, then.

···

On Thu, Dec 4, 2008 at 8:58 AM, Kyle Schmitt <kyleaschmitt@gmail.com> 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.

--
Avdi

Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

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?

···

On Thu, Dec 4, 2008 at 8:58 AM, Kyle Schmitt <kyleaschmitt@gmail.com> 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.

--
Avdi

Home: http://avdi.org
Developer Blog: Avdi Grimm, Code Cleric
Twitter: http://twitter.com/avdi
Journal: http://avdi.livejournal.com

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 Thu, Dec 4, 2008 at 10:45 AM, Avdi Grimm <avdi@avdi.org> 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