LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-21-2004, 07:15 AM   #1
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
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=pipes.Template()
m.debug('true')
m.append('mplayer -slave /some/were', '--')
n=m.open('/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?
 
Old 10-21-2004, 07:25 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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.
 
Old 10-21-2004, 09:20 PM   #3
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Original Poster
Rep: Reputation: 51
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?
 
Old 10-21-2004, 09:30 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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:
http://www.python.org/doc/faq/librar...put-and-output
 
Old 10-22-2004, 08:00 AM   #5
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Original Poster
Rep: Reputation: 51
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
 
Old 10-23-2004, 08:27 AM   #6
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Original Poster
Rep: Reputation: 51
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?
 
Old 10-23-2004, 09:04 AM   #7
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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.
 
Old 10-23-2004, 11:59 PM   #8
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Original Poster
Rep: Reputation: 51
thanks
 
Old 08-02-2006, 10:10 AM   #9
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Rep: Reputation: 30
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.

Thanks
 
Old 08-02-2006, 10:35 AM   #10
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,423

Rep: Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158Reputation: 1158
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
best practices for subprocs & pipes in python bardinjw Programming 0 11-28-2005 01:27 PM
about pipes kpachopoulos Programming 1 10-15-2005 01:37 PM
devices and pipes siemens Linux - General 1 03-23-2005 04:30 AM
Interleaving using pipes AquamaN Programming 1 09-28-2003 05:59 PM
Use of Named Pipes casey0999 Linux - Software 3 08-03-2003 02:21 PM


All times are GMT -5. The time now is 12:02 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration