Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Southampton, England
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C - Communicating with MPG123

    mpg123 is an MP3 player for Linux. It has a stdin interface, whereby if I launch mpg123 by typing:

    mpg123 -R asong.mp3

    I can then make requests to mpg123 via the stdin like:

    LOAD asong.mp3
    LOAD anothersong.mp3
    PAUSE

    I have got this much working, but I want to make a C Program that can do this. I tried writing a program that prints to stdout using printf, and then re-directeding the output of that to the input of mpg123, but for some reason it does not work:

    myprog > mpg123 -R asong.mp3

    Any ideas?

    Lloyd

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So if I understand correctly, you want to start an other program with some additional parameters?

    you can do that with spawnl

    Code:
    #include <process.h>
    
    spawnl(P_WAIT, "mpg123.exe", "mpg123.exe -R asong.mp3 ", NULL);
    I hope this works, I'm not used to program under Linux, actualy, I've never done it

    --maes
    If you don't succeed at first, redefine succes

  • #3
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Southampton, England
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Further Communication

    Ok, I see what your doing as I've just looked up that function.

    But is it possible for my program that spawned the mpg123 process to communicate to mpg123's STDIN? Is there a way of re-directing the std i/o so I can do this?

    Thanks,

    Lloyd

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't have any experiance with programming for linux, nor have I ever done this in windows. But the way I would go about this, is getting the handle to the program (mgp123)
    and then redirect the standard input to that program. In windows, I think the function SetStdHandle can do this. Don't know about linux.

    if linux doesn't work with handles, then I have no idea how you can identify the mgp123 program.

    -- Maes
    If you don't succeed at first, redefine succes

  • #5
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Southampton, England
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I believe this is a windows method. Thanks anyway.

    Somebody help me!!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •