From: Victor Reyes Date: 2008-07-22T04:44:48+09:00 Subject: Re: How to invoke an external program and get anything the pgm returns back ------=_Part_97411_12159629.1216669815570 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Mon, Jul 21, 2008 at 3:24 PM, Sandor Sz=FCcs wrote: > > On 21.07.2008, at 20:35, Victor Reyes wrote: > > I tried: >> Ruby script segment: >> rc =3D `/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= *. >> > > > irb> res =3D `ls file_not_exists` > ls: file_not_exists: No such file or directory > =3D> "" > irb> $?.exitstatus > =3D> 1 > > According to ri page Kernel.system also sets $? > > > $ qri Kernel.system > ---------------------------------------------------------- Kernel#system > system(cmd [, arg, ...]) =3D> 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=FCcs > -- > 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" =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D /usr/local/bin>cat test.rb #!/usr/local/ruby-1.8.6/bin/ruby -W0 puts "This is a Ruby script" exit 199 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D /usr/local/bin>cat test.ksh #!/bin/ksh echo "This is a Korn Shell script" exit 99 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Thank you Victor ------=_Part_97411_12159629.1216669815570--