escape a string for shell commands in Python -
this question has answer here:
- how escape os.system() calls in python? 10 answers
i'm interested escape string in python3.x, such as:
some_macro(a, b) into...
some_macro\(a,\ b\) ... can passed program (not gcc in case) define,
eg,
some_program -dsome_macro\(a,\ b\)="some expression" i expect shlex have functionality didn't find how , checked many similar questions already.
i don't mind write simple function this, seems kind of thing python include.
note: the program i'm passing argument wont accept:
-d"some_macro(a, b)"="some expression" ... expects first character identifier.
doing correctly means not having worry this. shell has worry spaces , quotes , parens; python not.
proc = subprocess.popen([..., "-dsome_macro(a, b)=some expression", ...], ...) 
Comments
Post a Comment