spawning a process

K

Kurt M. Dresner

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
 
H

Hal E. Fulton

----- Original Message -----
From: "Kurt M. Dresner" <[email protected]>
To: "ruby-talk ML" <[email protected]>
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
 
A

Armin Roehrl

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

Brian Candler

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?

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

Brian Candler

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

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

Eric Hodel

--gXx2FYK2AghGE4Yq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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.
=20
Any suggestions?

Take a look at rmp3 in raa:

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

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.

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--gXx2FYK2AghGE4Yq
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/QQnOMypVHHlsnwQRAhtfAJ4sH/Dn+dsZOepwm1Eo82Kk3iQo0ACgzcPi
4aSWtmn2/eiDT5LAbUs2CHw=
=rF51
-----END PGP SIGNATURE-----

--gXx2FYK2AghGE4Yq--
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top