[Tutor] Cmd line not correctly interpreted

Alan Gauld alan.gauld at yahoo.co.uk
Sat Jun 4 04:05:17 EDT 2016


On 04/06/16 02:01, Alan Outhier wrote:
> I'm working on a Python script to call "sox" to convert ;ogg files to .mp3s.

1    outname=fname+".mp3"
2    fname=ReSpace(fname)   # substitute " " with "\ "
3    outname=ReSpace(outname)
4    cmdline="sox " + fname + " " +outname
5    print cmdline
6    rtncode=os.system(cmdline)
7    if rtncode <> 0:
8        print "Bad return code (" + str(rtncode) + ") from sox command"
9        sys.exit()*

> ...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 *

> I can however cop-past that output to bash and it works fine.

It might be easier to use the subprocess call() function
and pass the filenames in that way. Also you could try upping the
verbosity of sox so it tells you more about the error.

I'd be suspicious of the filename format and try using
hard coded strings in raw format first:

outname = r"Carnegie Hall Jazz Band/Carnegie Hall Jazz Band/Frame for
 the Blues.mp3"

If that works it suggests your formatting function is not doing
what it should.

Another thing to try is to eliminate the complex filenames entirely
by copying the file to foo.ogg in the local directory. See if that
works. Then try a name with spaces in the current directory. Then a
directory name without spaces. etc etc.

By a process of elimination you can find out where things start
to fall over.

> Please help! I'll send the whole program if requested.

The ReSpace() function might be helpful.

But please send using plain text. Trying to reconstruct Python
code as I did above is extremely error prone.

-- 
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