5

I have the following working code in first.py:

import os 
os.system('cat python_better_than_java.wav')

which I can execute like this

python first.py |  ffmpeg -y -f wav -i pipe:0 -f mp3 - >hi.mp3

this works.

I want do this in a pythonic way, so I edited first.py to this:

import sys
with open('python_better_than_java.wav', 'rb') as content_file:
    content = content_file.read()
sys.stdout.write(content)

and executed it using:

python first.py | ffmpeg -y -f wav -i pipe:0 -f mp3 - >hi.mp3

but then it produces the following error:

pipe:0: Invalid data found when processing input

How can I reproduce cat in python?

5
  • What happens if you do python first.py > output and then diff output python_better_than_java.wav? Commented Sep 16, 2014 at 8:29
  • @Duncan Binary files t.py.wav and u.py.wav differ Commented Sep 16, 2014 at 8:45
  • It should work. Is the size of output equal to python_better_than_java.wav? What operating system / python version are you using? Commented Sep 16, 2014 at 10:15
  • 4kb size difference in file. but possible to play both file.i am using window 7 32 bit and python 2.7 Commented Sep 16, 2014 at 10:40
  • It's a shame this is a duplicate, 'cause there's was lot of rep to be had... Commented Sep 16, 2014 at 15:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.