spawning a process

Discussion in 'Ruby' started by Kurt M. Dresner, Aug 16, 2003.

  1. 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
    Kurt M. Dresner, Aug 16, 2003
    #1
    1. Advertising

  2. ----- Original Message -----
    From: "Kurt M. Dresner" <>
    To: "ruby-talk ML" <>
    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
    Hal E. Fulton, Aug 16, 2003
    #2
    1. Advertising

  3. 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" <>
    > To: "ruby-talk ML" <>
    > 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
    >
    >
    >
    >
    >======= End of Original Message =======<
    Kurt M. Dresner, Aug 16, 2003
    #3
  4. Kurt M. Dresner

    Armin Roehrl Guest


    > 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.
    Armin Roehrl, Aug 16, 2003
    #4
  5. 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?


    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.
    Brian Candler, Aug 16, 2003
    #5
  6. On Sun, Aug 17, 2003 at 03:48:39AM +0900, Brian Candler wrote:
    > > Any suggestions?

    >
    > 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.
    Brian Candler, Aug 16, 2003
    #6
  7. Kurt M. Dresner

    Eric Hodel Guest

    --gXx2FYK2AghGE4Yq
    Content-Type: text/plain; charset=us-ascii
    Content-Disposition: inline
    Content-Transfer-Encoding: quoted-printable

    Kurt M. Dresner () 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.
    >=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 - - 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--
    Eric Hodel, Aug 18, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    1,252
    Kevin Spencer
    Feb 8, 2005
  2. Marianne
    Replies:
    4
    Views:
    543
    Juan T. Llibre
    Jul 7, 2005
  3. Ashish

    spawning a process from webform1

    Ashish, Jul 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    327
    Ashish
    Jul 11, 2005
  4. Replies:
    8
    Views:
    5,112
    Oliver Wong
    May 24, 2006
  5. Uri Nix

    Process spawning in win32

    Uri Nix, Aug 22, 2004, in forum: Python
    Replies:
    0
    Views:
    280
    Uri Nix
    Aug 22, 2004
Loading...

Share This Page