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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -