-   Programming (
-   -   pipes in python? (

SciYro 10-21-2004 06:15 AM

pipes in python?
is there a way to get useful pipes in python?

what i need to do is create a pipe to mplayer so i can give it commands

so far all i could find was the module "pipes", but whenever i use it it outputs mplayer's output into the selected file .

import pipes
m.append('mplayer -slave /some/were', '--')'/tmp/1', 'w')

then mplayer start, but (thankfully) debug says something like "mplayer /some/were >/tmp/1" wich seems to be the exact opposite of what i want, well.,, i do needs mplayer output, but I'm not needing or wanting it now

i can get what i want on the command line by using a fifo, but it would be much better if i can go it without using one ..... i looked thru the tutorial on the python site, but it doesn't even at least say how to run a command, let alone run multiple ones at once, or pass info to programs.....

any ideas?

CroMagnon 10-21-2004 06:25 PM

Maybe try out the pty module instead - from my limited tests (I'm not at home with X, and I can't correctly gauge how well it's working over SSH) mplayer doesn't play so nicely with pure pipes.

SciYro 10-21-2004 08:20 PM

i guess thats why its been freezing up only about 2 seconds after playing ... thats the closet i get unless the pipe is backwards from what i want ...

thanks.... ill look into the pty module, if that don't work, perhaps just use fifo like on the command line would work?

CroMagnon 10-21-2004 08:30 PM

Usually a process freezes up because a pipe (usually stdout) is 'full' and waiting for you to read it - if you continually read mplayer's output, it should keep going (I had this problem trying to embed an mplayer window in my own app). I also found a nice FAQ entry on this, here:

SciYro 10-22-2004 07:00 AM

ah, yes, that pexpect modules solves the problem, kinda.. (just need to go back to the tutorials i guess..), and like you said it was because i need to read the output

at least i can play files now, and have basic control, tho its a shame mplayer doesn't output how long the file is, just how longs its been playing for (until i telled mplayer to be quiet if it cant coff up what i need to know)

thanks everyone

SciYro 10-23-2004 07:27 AM

just another quick question (just cause i don't like making new threads)

in python when i tell it code (by running python first so it will let me type the code to learn) when i run a command like "m=os.system('blabla')" it prevents me from typing in new commands. my question is this: is this the same for a script file? will it lock up so that it will prevent further execution of a script until the previous command finishes?

CroMagnon 10-23-2004 08:04 AM

os.system will block unless the program detaches and runs in the background, or you deliberately put it in the background with &. os.popen and friends will not block, because obviously you need to be able to read and/or write the relevant pipes.

SciYro 10-23-2004 10:59 PM


nutthick 08-02-2006 09:10 AM

SciYro: I'm trying to get MPlayer to work off pipes using bash but I'm having problems with the pipe blocking. You mentioned in your post that you could get the fifo working in bash. If possible, can you please post your fifo script, so I can figure out where I'm going wrong.


sundialsvcs 08-02-2006 09:35 AM

All pipes are buffers, with a limited capacity. Once a pipe becomes full, writers are blocked. Once a pipe becomes empty, readers are blocked. The purpose of a pipe is not to store data but only to communicate it, and the buffering provides a "flexible hose" so that the processes are less likely to execute in a lock-step fashion.

All times are GMT -5. The time now is 09:02 AM.