[Q] how can I start a shell process and return immediately?

Hello,

···

On 9/28/07, Stephen Bannasch <stephen.bannasch@deanbrook.org> 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.

When I try this from a Ruby program the program blocks until the Java
program is terminated.

There may be another way, but the first thing that came to mind for me
was just to launch it in another thread:

Thread.new { `java -cp <classpath> <main_class>` }

Cameron

Hello,

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.

When I try this from a Ruby program the program blocks until the Java
program is terminated.

There may be another way, but the first thing that came to mind for me
was just to launch it in another thread:

Thread.new { `java -cp <classpath> <main_class>` }

* Thanks Cameron,

That worked, I hadn't used threads before and they were what I needed.

* Thanks Sebastion,

I thought I had tried this:

  system("some_command&")

and it didn't work -- but it was late and I needed to sleep -- today that works fine -- so obviously I wasn't thinking as clearly as I could have been.

* Thanks 7stud,

IO.popen is interesting, I'm playing with your simple test programs and reading chapter 11 in the Pickaxe book.

···

On 9/28/07, Stephen Bannasch <stephen.bannasch@deanbrook.org> wrote:

Stephen Bannasch wrote:

* Thanks 7stud,

IO.popen is interesting, I'm playing with your simple test programs and
reading chapter 11 in the Pickaxe book.

You can consider the sleep(4) statement in the subprocess as a stand in
for some calculation or task that takes 4 seconds to execute.

···

--
Posted via http://www.ruby-forum.com/\.