[Tutor] Cmd line not correctly interpreted
Steven D'Aprano
steve at pearwood.info
Sat Jun 4 04:13:44 EDT 2016
On Fri, Jun 03, 2016 at 06:01:48PM -0700, Alan Outhier wrote:
> I'm working on a Python script to call "sox" to convert ;ogg files to .mp3s.
>
> In the following segment...:
>
> *1 outname=fname+".mp3"2 fname=ReSpace(fname) # substitute " " with
> "\ "3 outname=ReSpace(outname)4 cmdline="sox " + fname + " "
> +outname5 print cmdline6 rtncode=os.system(cmdline)7 if rtncode <>
> 0:8 print "Bad return code (" + str(rtncode) + ") from sox
> command"9 sys.exit()*
Your code is a mess. Try sending plain text instead of "rich text". When
you send rich text, your mail client will mangle the line breaks and put
them where ever it sees fit.
Also, there's no need for line numbers. Especially not when there are
only nine lines.
> ...I DO get the error trap (every time). Line 5 causes the following (for
> example) to be printed:
>
>
> *sox Carnegie\ Hall\ Jazz\ Band/Carnegie\ Hall\ Jazz\ Band/Frame\ for\ the\
> Blues Carnegie\ Hall\ Jazz\ Band/Carnegie\ Hall\ Jazz\ Band/Frame\ for\
> the\ Blues.mp3*
> *Bad return code (512) from sox command *
According to the sox man page, it will only return 0, 1 or 2, not 512:
Exit status is 0 for no error, 1 if there is a problem with
the command-line parameters, or 2 if an error occurs during
file processing.
http://sox.sourceforge.net/sox.html#DIAGNOSTICS
but I think that is a lie, as I can reproduce your error, without even
using spaces:
py> os.system("sox ab cd")
sox: Can't open input file 'ab': No such file or directory
512
I'm surprised that you don't see the error message printed by sox. Are
you redirecting stderr to a file or something? If so, please check the
file.
You are using a relative path starting with "Carnegie\ Hall...". You
probably should use an absolute path.
--
Steve
More information about the Tutor
mailing list