...

View Full Version : C - Communicating with MPG123



lsbt100
02-05-2003, 05:58 PM
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

maes
02-05-2003, 06:32 PM
So if I understand correctly, you want to start an other program with some additional parameters?

you can do that with spawnl



#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 :D

--maes

lsbt100
02-05-2003, 06:53 PM
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

maes
02-05-2003, 07:16 PM
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

lsbt100
02-06-2003, 08:50 PM
I believe this is a windows method. Thanks anyway.

Somebody help me!!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum