From: Andreas M. <And...@we...> - 2010-03-28 18:52:56
|
-----Ursprüngliche Nachricht----- Von: kevin parks <kp...@me...> Gesendet: 28.03.2010 17:06:55 An: sox...@li... Betreff: Re: [SoX-users] sox & python (with subprocess) > >To answer my own question, i was thrown off by the format below. You can also do it just as you would with the os module. Just specify the whole sucker on one line with call method as so: > >subprocess.call('sox -V3 -D -S in.aif -b16 out-01.aif rate -s -v 44100', shell=True) > >with the shell=True at the end... seems to to work fine. Hi Kevin, there was a reason for showing you my version with every command line argument being one item in python list. As soon as you work with shell=True you get all evil of handling shell special characters. And it you want to do a generic os.walk you NEVER know how the files are named. E.g. what happens when someone called a infile 'haha; rm -rf *;' When you call it it would be called as subprocess.call('sox -V3 -D -S haha; rm -rf *; -b16 out-01.aif rate -s -v 44100', shell=True) this results in sox -V3 -D -S haha (probably syntax error) rm -rf * -b16 out-01.aif rate -s -v 44100 (probably syntax error) But the second part would be executed with bad effects. You do yourself a favour to call the whole thing as: subprocess.call( ('sox', '-V3', '-D', '-S', 'in.aif', '-b16', 'out-01.aif', 'rate', '-s', '-v', '44100') ) INHO the whole thing has an advantage: You can prepare the constant caling options once and only change the command line arguments which change (e.g. the filenames). You don't need to do string manipulation for every invocation, just changing one or two elements of a list. Best regards Andreas Mock |