Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-05-2003, 05:58 PM   PM User | #1
lsbt100
New to the CF scene

 
Join Date: Dec 2002
Location: Southampton, England
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
lsbt100 is an unknown quantity at this point
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
lsbt100 is offline   Reply With Quote
Old 02-05-2003, 06:32 PM   PM User | #2
maes
Regular Coder

 
Join Date: Jul 2002
Location: Belgium
Posts: 124
Thanks: 0
Thanked 0 Times in 0 Posts
maes is an unknown quantity at this point
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
maes is offline   Reply With Quote
Old 02-05-2003, 06:53 PM   PM User | #3
lsbt100
New to the CF scene

 
Join Date: Dec 2002
Location: Southampton, England
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
lsbt100 is an unknown quantity at this point
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
lsbt100 is offline   Reply With Quote
Old 02-05-2003, 07:16 PM   PM User | #4
maes
Regular Coder

 
Join Date: Jul 2002
Location: Belgium
Posts: 124
Thanks: 0
Thanked 0 Times in 0 Posts
maes is an unknown quantity at this point
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
maes is offline   Reply With Quote
Old 02-06-2003, 08:50 PM   PM User | #5
lsbt100
New to the CF scene

 
Join Date: Dec 2002
Location: Southampton, England
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
lsbt100 is an unknown quantity at this point
I believe this is a windows method. Thanks anyway.

Somebody help me!!!!
lsbt100 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 PM.


Advertisement
Log in to turn off these ads.