[Tutor] Does python change subprocess based on whether it is run in the interactive shell or not
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Oct 29 09:23:56 EDT 2022
On 28/10/2022 12:38, Nathan Smith wrote:
> p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> stdin=subprocess.PIPE, stderr=subprocess.PIPE)
> [stdout, stderr]=p.communicate(data)
The square brackets should not be needed. Unpacking
will work based on the comma alone.
> Where data is some data taken from io.bytesIO.read
>
> And cmd is a command for ffmpeg like so:
>
> cmd="ffmpeg/ffmpeg.exe -f wav -ac 2 -i - -f mp3 -ab 128000 - -y"
so far so good.
> When run in an interactive shell this works like a charm. When run in a
> script file, this breaks.
Breaks? How?
Error message? Bad data? No data?
Give us a clue.
> At first I thought it was an issue with
> FFMPEG, but now I'm wondering if python is changing something under the
> hood?
How are you running the script file?
Is it the same user environment as the interactive Python session
or via a cron job or similar?
> When running from a script, should I be using shell=True?
Probably not. shell=True simply says to read the command
in a shell environment expanding wildcards etc. You don't seem
to be using anything that needs shell expansion.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list