How are you running the second script?
If you do it the right way, you won't invoke a shell at all, so you don't need to add quotes (which are used by shells to decide how to split arguments into an argv
array), and instead can pass the exact argv array you want.
For instance:
subprocess.Popen(['example.py', '--q', request.args.get('search_key', '')])
No quotes added, but no quotes needed -- the result from request.args.get('search_key, '')
is passed as a single argument. Note that this only works if you do not pass shell=True
.
See the subprocess module documentation for details -- on collecting stdout and stderr, checking exit status, and much more.