On Jul 9, 2009, at 5:13 PM, Enling Li wrote:
> I have another quetion related to fire off a back ground shell process
> on a remote Linux.
>
> require "net/ssh"
>
> ssh = Net::SSH.start( '10.0.77.87', 'toor', :password=>'logapp')
> ssh.exec!("/root/test.pl &")
> ssh.close
> puts "I want to be here immediately, but not"
>
> The above code hangs also because test.pl contains a long sleep and do
> nothing. Can someone offer me a help?
>
> Thank you in advance.
>
> Enling
>
> Stephen Bannasch wrote:
>> I want to start a Java program from a Ruby program and have the Java
>> program run in another process and have control returned to my Ruby
>> program as soon as the Java process starts up successfully.
>>
>> I can do this from a shell by suffixing an '&':
>>
>> java -cp <classpath> <main_class>&
>>
>> starts the Java program in a background process thread and returns
>> control the shell.
>>
>> When I try this from a Ruby program the program blocks until the Java
>> program is terminated.
If your system has the `setsid` (set session id) program (and the
underlying system call), then you could try:
ssh.exec!("setsid /root/test.pl")
or
setsid java -cp YOURCLASSPATH MainClass
but you may wish to redirect output.
ssh.exec!("setsid /root/test.pl >/tmp/test.log 2>&1")
-Rob
Rob Biedenharn
http://agileconsultingllc.comRob@...