[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby hangs when executing a another program

Christopher Rasch

7/31/2006 7:53:00 PM

If I run the following command on the command line, it executes
without difficulty:

crasch$ ssh -l root localhost /Library/FrontBase/bin/FBExec &
[1] 4340

crasch$ ps -aux | grep 'FBExec'
root 4344 0.0 -0.0 28372 460 ?? Ss 1:43PM
0:00.01 /Library/FrontBase/bin/FBExe

If I run the same command in the ruby interpreter, the interpreter
hangs until I issue a break command ("Ctrl-C" ) :

irb(main):127:0> %x{ ssh -l root localhost /Library/FrontBase/bin/
FBExec & }
^CIRB::Abort: abort then interrupt!!
from /usr/local/lib/ruby/1.8/irb.rb:81:in `irb_abort'
from /usr/local/lib/ruby/1.8/irb.rb:243:in `signal_handle'
from /usr/local/lib/ruby/1.8/irb.rb:66:in `start'
from (irb):127
from :0

Although the command hangs, the process is started:

crasch:~/Projects/trunk/DeployScripts crasch$ ps -aux | grep 'FBExec'
root 4282 0.0 -0.0 28372 460 ?? Ss 1:39PM
0:00.01 /Library/FrontBase/bin/FBExec
crasch 4296 0.0 -0.0 27812 4 p1 R+ 1:42PM 0:00.00
grep FBExec

If I run the command after the FBExec process has been started, I get
the following message:

irb(main):129:0> %x{ ssh -l root localhost /Library/FrontBase/bin/
FBExec & }
=> "2006-07-31 13:53:21 Cannot bind listen socket - FBExec may
already be running\n"

The exit code after running the command on the command line is


The same thing happens if I run the command inside a script. I've
tried stepping through the command using the debugger, it doesn't
appear to be able to step through the command expansion code (at
least, I've not figured it out yet).

Note that I can execute the command with

irb(main):137:0> system("ssh -l root localhost /Library/FrontBase/bin/
FBExec &")
=> true

Why the discrepancy in behavior? Thanks for any help you may wish
to provide.

Chris





2 Answers

Nobuyoshi Nakada

8/1/2006 3:06:00 AM

0

Hi,

At Tue, 1 Aug 2006 04:52:42 +0900,
Christopher Rasch wrote in [ruby-talk:205273]:
> If I run the same command in the ruby interpreter, the interpreter
> hangs until I issue a break command ("Ctrl-C" ) :
>
> irb(main):127:0> %x{ ssh -l root localhost /Library/FrontBase/bin/
> FBExec & }

%x and `` wait until the command exits and read the output from
it.

--
Nobu Nakada

S Wayne

8/1/2006 3:25:00 AM

0

Use fork and exec:

prc = fork
if prc
puts "This is the parent process, child PID is: #{prc}"
else
puts "child process will exec our shell command"
exec("ssh -l root localhost /Library/FrontBase/bin/FBExec")
puts "This line will never be seen because exec doesn't return."
end
puts "Parent continues here"