Spawning a process

Hi,

I’m looking through the Ruby documentation and I’m trying to find an
equivalent to the Python: “pid = os.spawnv(os.P_NOWAIT, program, args)”.

I want to play a sound file in a new process, but I want the ability to
terminate, stop, and continue this process from the file I am in.

Any suggestions?

-Kurt

I suppose that depends in part on what OS you’re on
and how the sound player exposes its controls.

If you’re on Linux or the equivalent, fork and pipe
will work. There’s also exec and so on. Don’t think
these work on Windows.

You might look into wrapping the sound player in a
drb server that you can then invoke from anywhere.

Hal

···

----- Original Message -----
From: “Kurt M. Dresner” kdresner@cs.utexas.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, August 16, 2003 1:12 PM
Subject: spawning a process

Hi,

I’m looking through the Ruby documentation and I’m trying to find an
equivalent to the Python: “pid = os.spawnv(os.P_NOWAIT, program, args)”.

I want to play a sound file in a new process, but I want the ability to
terminate, stop, and continue this process from the file I am in.

Any suggestions?


Hal Fulton
hal9000@hypermetrics.com

> I want to play a sound file in a new process, but I want the ability to > terminate, stop, and continue this process from the file I am in. > > Any suggestions?

pid = fork {
play_sound(…)
}

Then look in the Process module for all the things you can do with a
PID.

hth,

···

On Sun, 17 Aug 2003 03:12:24 +0900 “Kurt M. Dresner” kdresner@cs.utexas.edu wrote:


Ryan Pavlik rpav@users.sf.net

“I have tasted sweet, sweet invincibility.
It tastes like varnish.” - 8BT

pid = fork {
exec(program,*args)
}

then you can send signals to that particular pid.

Alternatively, if your command is controlled by messages sent on its stdin,
then:

cmd = IO.popen(“program args”,“w”)
cmd.puts “play” # or whatever

Regards,

Brian.

···

On Sun, Aug 17, 2003 at 03:12:24AM +0900, Kurt M. Dresner wrote:

I’m looking through the Ruby documentation and I’m trying to find an
equivalent to the Python: “pid = os.spawnv(os.P_NOWAIT, program, args)”.

I want to play a sound file in a new process, but I want the ability to
terminate, stop, and continue this process from the file I am in.

Any suggestions?

In addition to all of the other responses you’ve received, Ruby’s Shell
class (part of the standard distribution) provides a lot of
infrastructure for spawning new processes, including job control and
threading.

Regards,

Mark

···

On Saturday, August 16, 2003, at 02:12 PM, Kurt M. Dresner wrote:

Hi,

I’m looking through the Ruby documentation and I’m trying to find an
equivalent to the Python: “pid = os.spawnv(os.P_NOWAIT, program,
args)”.

I want to play a sound file in a new process, but I want the ability to
terminate, stop, and continue this process from the file I am in.

Any suggestions?

-Kurt

Take a look at rmp3 in raa:

http://raa.ruby-lang.org/list.rhtml?name=rmp3

It allows you to play/stop, etc mpg123/321, and is pretty easy to follow
(I hijacked it for Webplayer, also in the RAA). Even if you’re not
using mp3 files, it may be worth a look.

···

Kurt M. Dresner (kdresner@cs.utexas.edu) wrote:

I want to play a sound file in a new process, but I want the ability to
terminate, stop, and continue this process from the file I am in.

Any suggestions?


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

I’m using Debian GNU/Linux, and I want to use mpg123 and ogg123.

-Kurt

···

On Sun, Aug 17, 2003 at 03:17:50AM +0900, Hal E. Fulton wrote:

----- Original Message -----
From: “Kurt M. Dresner” kdresner@cs.utexas.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, August 16, 2003 1:12 PM
Subject: spawning a process

Hi,

I’m looking through the Ruby documentation and I’m trying to find an
equivalent to the Python: “pid = os.spawnv(os.P_NOWAIT, program, args)”.

I want to play a sound file in a new process, but I want the ability to
terminate, stop, and continue this process from the file I am in.

Any suggestions?

I suppose that depends in part on what OS you’re on
and how the sound player exposes its controls.

If you’re on Linux or the equivalent, fork and pipe
will work. There’s also exec and so on. Don’t think
these work on Windows.

You might look into wrapping the sound player in a
drb server that you can then invoke from anywhere.

Hal


Hal Fulton
hal9000@hypermetrics.com

======= End of Original Message =======<

I suppose that depends in part on what OS you’re on
and how the sound player exposes its controls.

If you’re on Linux or the equivalent, fork and pipe
will work. There’s also exec and so on. Don’t think these work on
Windows.

Alternatively, if stuck on Windows, experiment with non-MS-compiled
ruby-versions: cygwin, djgpp, …
http://ftp.ruby-lang.org/pub/ruby/binaries/

I know too little about the Windows-world to tell you which
works with what implemenation, but I once got read of a nasty
socket problem in ruby … simply by switching to the cygwin version.

Oh, beware that the child will share stdin / stdout / stderr with your main
process. If you don’t want that, you can reopen them:

pid = fork {
  STDIN.reopen('/dev/null')
  # ditto for STDOUT and/or STDERR if you wish
  exec(program,*args)
}

Regards,

Brian.

···

On Sun, Aug 17, 2003 at 03:48:39AM +0900, Brian Candler wrote:

Any suggestions?

pid = fork {
exec(program,*args)
}