I've been writing a little program for a radio transmitter I built with the Raspberry Pi. Everything had been working fine up until I used subprocess for the handling of the command line utilities needed to run the said program.

The question I pose to everyone here is how should I go about converting the below command (which uses pipes) into code that utilises 'subprocess.call()'


Code:
ffmpeg -i input.mp3 -f s16le -ar 22.05k -ac 1 - | sudo ./pifm -


Many thanks!

Code:
ffmpeg = Popen(["ffmpeg","-i","input.mp3","-f","s161e","-ar","22.05k","-ac","1","-",stdout=subprocess.PIPE)
sp = Popen(["sudo","./pifm","-"],stdin=ffmpeg.stdout)


Do what you want with the output/return code by checking them.
Cheers, elfprince, that's great! I assume it will work the same with subprocess.call()?
The second one can use subprocess.call, but you need to have a Popen handle to ffmpeg to get the pipe from.

I recommend following that with sp.wait() which has the same return value as the call would have.
I assume I'd also be best to kill the main process too, when it's done.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement