Unix Inter Process Communication programming question: pipes and the like.

notfred

Lifer
Feb 12, 2001
38,241
4
0
Ok, so lets say I've got a process running that accepts input on STDIN. Let's also assume that I know the PID of this process. I'm writing another program that should be able to send data so that the first program should receive it on STDIN.

This is probably really simple, but I've never done it before. I'll be writing it in perl, but if you want to give me examples in C or something that's fine. Any help you can give is appreciated. :)
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
I don't think* you can get at the stdin/stdout/stderr of other running processes; it needs to be set up before they run. i.e. one of the processes needs to exec the other, or they both need to be exec'd by the same process -- this is what a shell does when you do, say, echo foo > blah. You could set up a named pipe with mkfifo(1), which is basically just a pipe with a filename.

* I might be wrong but I'm pretty sure that's the case ;)
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Bah, that's no fun. What I'm trying to do is basically write a remote control for mplayer. I want apache to run a perl script that controls an already running mplayer. I'd also rather not rewrite apache or mplayer if I don't have to.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
If mplayer's authors have any imagination whatsoever :)P), mplayer should already be able to do this somehow. How is mplayer started?
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
I don't know...

Mplayer would have to accept inputs from stdin wouldn't it? It's something that the programmers would have to setup beforehand....

something like echo ~/imadinasorus.mp3 | mplayer?

Maybe you would have to write a java or perl front end that you can control over a web interface....

This sort of thing is why they are making gstreamer, they have scripting hooks into it alread y so people could drum out their own interfaces or scripts. That way it would be a simple thing to write a perl script you can press buttons thru a web interface. The way I figure it is that mplayer folks would already have to allowed for this sort of thing, if not it could require some hacking to the mplayer code to do it. (but you shouldn't listen to me to closely, I don't realy know what I am talking about, this is just speculation.)

mabye check out other mplayer front ends and see if they have a standard way to do it

There are also network jutebox style programs that maybe you can get pointers off of.

I'd figure the best bet for something like this without all the pain would be gstreamer, but I don't know how far along in it's developement it is. check it out here. I don't know if it has perl bindings, it should have some, perl is damn popular. They are advertising new python bindings in the news sections. I like python, so that makes me happy.

But my python (and programming in general) skills are still the pre-pre-alpha infancy form. Last night I wrote my first program that is remotely usefull for anything, a python program that generates bash scripts from a simple config file for use with the ratmenu/ratmen program. (do nested menus, and incorporate bash commnds with more then one "command" per menu entry, that sort of semi-useless stuff)
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Originally posted by: BingBongWongFooey
If mplayer's authors have any imagination whatsoever :)P), mplayer should already be able to do this somehow. How is mplayer started?

xmms has a plugin that sets up some pipes so you can echo commands like "PLAY", "PAUSE", "STOP", "VOLUME xx", etc. to the pipe and control it :).
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Bah, this is a pain in the ass. Does anyone make a DVD player that plays MPEg4 files that I can just buy? My linux box freaked out on me and I can't get my vid card to work right since last night anyway...

Ugh, computers suck.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
So, VLC has support for remote control over HTTP already, and it works pretty well even though the interface sucks, soI'm going to modify that instead of playing with mplayer.