Using $* as part of a parameter for os.system in python -
the command:
make foo -f $*
has different functionality when called command line versus when called python script follows:
import os os.system(make foo -f $*)
as stated here: http://tldp.org/ldp/abs/html/internalvariables.html#appref $* in bat file positional parameters seen single word.
python seems parsing "$*". there anyway around , replicate same functionality?
i realise can write .bat script , call python hoping more eloquent.
as point out, $* has no special meaning in python. comprehension done entirely whatever shell using. if want pass positional parameters passed script command, can try following
import os, sys os.system("make foo -f {}".format(" ".join(sys.argv[1:])))
please note os.system
deprecated. should use
import subprocess, sys subprocess.check_call("make foo -f {}".format(" ".join(sys.argv[1:])), shell=true)
instead.
edit
as suggested in comments, 1 should avoid using shell=true
whenever command built "untrusted" input, such command line of program. therefore better alternative use
import subprocess, sys subprocess.check_call(['make', 'foo', '-f'] + sys.argv[1:])
Comments
Post a Comment