From: Robert Klemme Date: 2009-06-20T05:05:08+09:00 Subject: Re: Capturing System Call Return Values? On 19.06.2009 20:52, Tyler Knappe wrote: > Roger Pack wrote: >> Tyler Knappe wrote: >>> I'm attempting to use Ruby to make system calls (in this case python >>> scripts) which return values, The term "system call" is usually used to denote calls of functions in the system library (e.g. open(), read(), fork()). What you mean would rather be called an "external process". (Of course that's done via a system call as well, but this is just one of a multitude of available system calls.) >>> that I then hand off to Ruby on Rails to >>> populate a webpage. However, I've run into a problem with capturing the >>> return values of system calls. >> appears to be $?, from some google work >> http://74.125.155.132/search?q=cache:lNLxDxyXbj4J:www.rubyist.net/~slagell/ruby/globalvars.html+ruby+global+variables&cd=1&hl=en&ct=clnk&gl=us&client=firefox-a > > $? exit status of last executed child process > > I don't think is quite correct. I tried it and was returned a value of > 0. Why would that mean that the statement above is not correct? > I've found a work around by splitting the returned string using > [string].split(' ') but this isn't as elegant as I had hoped. Now I am not sure what you want: are you interested in the exit status of a process that was executed? E.g. irb(main):010:0> system "false" => false irb(main):011:0> $? => # irb(main):012:0> system "echo", "test" test => true irb(main):013:0> $? => # irb(main):014:0> Or do you mean the output of an external process, e.g. irb(main):001:0> dir = `ls -dl` => "drwxrwxrwt+ 2 robert Benutzer 0 Jun 19 21:53 .\n" irb(main):002:0> Your last statement seems to indicate the latter. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/