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.
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.
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.
Thank you, Rob for the quick reply and help. I tried the commmand you
enclosed in the mail. It did not work out. I still got hang at the
exec() command.
Here are the options I did. They behave the same. They don't work. By
the way, my linux system has setsid().
Would just dropping the ssh section into it's own thread accomplish your
task? That seems like a rather simple way of getting what you want.
John
···
On Thu, Jul 9, 2009 at 4:53 PM, Enling Li <enling.li@loglogic.com> wrote:
Thank you, Rob for the quick reply and help. I tried the commmand you
enclosed in the mail. It did not work out. I still got hang at the
exec() command.
Here are the options I did. They behave the same. They don't work. By
the way, my linux system has setsid().
Thank you, Rob for the quick reply and help. I tried the commmand you
enclosed in the mail. It did not work out. I still got hang at the
exec() command.
Here are the options I did. They behave the same. They don't work. By
the way, my linux system has setsid().
or perhaps bash, /bin/sh, or /bin/bash in place of sh
Of course, I'm assuming that you are verifying that you can ssh manually and run these commands yourself. (If not, get to a command that works even after you log out manually.)
-Rob
···
On Jul 9, 2009, at 7:53 PM, Enling Li wrote:
Rob Biedenharn wrote:
On Jul 9, 2009, at 5:13 PM, Enling Li wrote:
The above code hangs also because test.pl contains a long sleep and do
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:
I tried that before. The thread won't solve the issue because once child
thread established it does the same way as main tread. When the main
thread terminates, the child gets killed also. It ends up nothing
happened to the shell command.
Thanks.
Enling
John W Higgins wrote:
···
On Thu, Jul 9, 2009 at 4:53 PM, Enling Li <enling.li@loglogic.com> > wrote:
Would just dropping the ssh section into it's own thread accomplish your
task? That seems like a rather simple way of getting what you want.
or perhaps bash, /bin/sh, or /bin/bash in place of sh
Of course, I'm assuming that you are verifying that you can ssh
manually and run these commands yourself. (If not, get to a command
that works even after you log out manually.)
Are you sure you are properly connecting to the server? Have you tried just
running something like ls and getting back a result? I just tried running a
simple script that sleeps for 100 seconds and it ran just fine after the
remote app was finished.
If that still leaves you in trouble - you might want to look into Screen
which is designed to run apps detached from the login shell so that would
certainly be of use if needed. This is the command I use to run an app
detached - screen -D -m command.rb
John
···
On Thu, Jul 9, 2009 at 6:34 PM, Enling Li <enling.li@loglogic.com> wrote:
I tried that before. The thread won't solve the issue because once child
thread established it does the same way as main tread. When the main
thread terminates, the child gets killed also. It ends up nothing
happened to the shell command.
Thanks.
Enling
John W Higgins wrote:
> On Thu, Jul 9, 2009 at 4:53 PM, Enling Li <enling.li@loglogic.com> > > wrote:
>
>>
> Would just dropping the ssh section into it's own thread accomplish your
> task? That seems like a rather simple way of getting what you want.
>
> John
The key is I don't want to wait for the remote to finish. If I wait for
remote to complete, I don't have problem.
Thanks.
Enling
John W Higgins wrote:
···
Are you sure you are properly connecting to the server? Have you tried
just
running something like ls and getting back a result? I just tried
running a
simple script that sleeps for 100 seconds and it ran just fine after the
remote app was finished.
If that still leaves you in trouble - you might want to look into Screen
which is designed to run apps detached from the login shell so that
would
certainly be of use if needed. This is the command I use to run an app
detached - screen -D -m command.rb
The key is I don't want to wait for the remote to finish. If I wait for
remote to complete, I don't have problem.
Sorry I used the wrong wording - I meant that Machine A connected to Machine
B using Net::SSH and ran a script that slept for 100 seconds. Machine A then
disconnected without blocking and Machine B continued to execute the script
that was sleeping away. Again make sure you are connecting because you could
easily be not getting to the server at all - the block could just as easily
be a connection block and not an execution block. And if you are connecting
and still for some reason blocking - Screen is definitely the answer because
that is exactly what is it designed for.
John
···
On Thu, Jul 9, 2009 at 8:06 PM, Enling Li <enling.li@loglogic.com> wrote:
Thanks.
Enling
John W Higgins wrote:
> Are you sure you are properly connecting to the server? Have you tried
> just
> running something like ls and getting back a result? I just tried
> running a
> simple script that sleeps for 100 seconds and it ran just fine after the
> remote app was finished.
>
> If that still leaves you in trouble - you might want to look into Screen
> which is designed to run apps detached from the login shell so that
> would
> certainly be of use if needed. This is the command I use to run an app
> detached - screen -D -m command.rb
>
> John