How to invoke an external program and get anything the pgm returns back

Team,

I have a Ruby script which might invoke an external program.
The external program could be written in: Ruby, Perl, KSH, CSH, BSH, Etc.
The invoked program might return a value in the the form of a return code.
For example, a KSH script might execute an *exit 99* stmt and which value I
would like to capture in the invoker, Ruby script.

I tried:
Ruby script segment:
      rc = `/usr/local/bin/script_name`

I also tried in the Ruby caller script:
     system("/usr/local/bin/script_name")

KSH:
exit 99

But *rc* does not have anything of value. It has either *true* or *false*.

···

========================

Also, using Ruby to Ruby I still can't get a Ruby script called another Ruby
script, have the called script returns a value and have the invoker Ruby
script get the value.

Is there anyway to get what I described above?

Thank you

Victor

Team,

I have a Ruby script which might invoke an external program.
The external program could be written in: Ruby, Perl, KSH, CSH, BSH, Etc.
The invoked program might return a value in the the form of a return code.
For example, a KSH script might execute an *exit 99* stmt and which value I
would like to capture in the invoker, Ruby script.

The global variable $? holds the exit status. If you require 'English'
then you can use the name $CHILD_STATUS instead of $?

I tried:
Ruby script segment:
     rc = `/usr/local/bin/script_name`

I also tried in the Ruby caller script:
    system("/usr/local/bin/script_name")

KSH:
exit 99

But *rc* does not have anything of value. It has either *true* or *false*.

Also, using Ruby to Ruby I still can't get a Ruby script called another Ruby
script, have the called script returns a value and have the invoker Ruby
script get the value.

Is there anyway to get what I described above?

Thank you

Victor

Jim

···

On Mon, Jul 21, 2008 at 2:35 PM, Victor Reyes <victor.reyes@gmail.com> wrote:
--
Jim Menard, jimm@io.com, jim.menard@gmail.com
http://www.io.com/~jimm/

I tried:
Ruby script segment:
      rc = `/usr/local/bin/script_name`

I also tried in the Ruby caller script:
     system("/usr/local/bin/script_name")

KSH:
exit 99

Ask $? to get the information.
$?.exitstatus

But *rc* does not have anything of value. It has either *true* or *false*.

res = `ls file_not_exists`

ls: file_not_exists: No such file or directory
=> ""

$?.exitstatus

=> 1

According to ri page Kernel.system also sets $?

$ qri Kernel.system
---------------------------------------------------------- Kernel#system
      system(cmd [, arg, ...]) => true or false

···

On 21.07.2008, at 20:35, Victor Reyes wrote:
------------------------------------------------------------------------
      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.

hth. regards, Sandor Szücs
--

Great! It works!
Here is what I have:

/tmp>cat pg1
#!/usr/local/ruby-1.8.6/bin/ruby -W0
puts "Calling /usr/local/bin/test.rb"
system("/usr/local/bin/test.rb")
puts $?.exitstatus
puts "Calling /usr/local/bin/test.ksh"
system("/usr/local/bin/test.ksh")
puts $?.exitstatus
puts "Now exiting"

···

On Mon, Jul 21, 2008 at 3:24 PM, Sandor Szücs <sandor.szuecs@fu-berlin.de> wrote:

On 21.07.2008, at 20:35, Victor Reyes wrote:

I tried:

Ruby script segment:
     rc = `/usr/local/bin/script_name`

I also tried in the Ruby caller script:
    system("/usr/local/bin/script_name")

KSH:
exit 99

Ask $? to get the information.
$?.exitstatus

But *rc* does not have anything of value. It has either *true* or *false*.

> res = `ls file_not_exists`
ls: file_not_exists: No such file or directory
=> ""
> $?.exitstatus
=> 1

According to ri page Kernel.system also sets $?

$ 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.

hth. regards, Sandor Szücs
--

=============
/usr/local/bin>cat test.rb
#!/usr/local/ruby-1.8.6/bin/ruby -W0
puts "This is a Ruby script"
exit 199

/usr/local/bin>cat test.ksh
#!/bin/ksh
echo "This is a Korn Shell script"
exit 99

And this is the result:

Calling /usr/local/bin/test.rb
This is a Ruby script
199
Calling /usr/local/bin/test.ksh
This is a Korn Shell script
99
Now exiting

Thank you

Victor