Ruby hangs when executing a another program

C

Christopher Rasch

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
 
N

nobu

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

N Okia

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top