why are '(single quote) or "(double quote) not allowed in subprocess.check_output() in python? -
i using subprocess.check_output() method execute commands within python script.
there commands need "(double quotes) present in syntax. here's 1 example:
>drozer console connect -c "run app.package.info -a com.package.name"
it throws error if remove "(double quotes) above command.
i did following :
string = '\"run app.package.info -a com.package.name\"' command = ['/usr/bin/drozer','console','connect','-c',string] output = subprocess.check_output(command)
this yields me error:
*** unknown syntax: "run app.package.info -a com.package.name"
please note : commands without quotes running through subprocess.check_output, code works properly.
how can solve issue of quotes? highly appreciated.
thanks
you don’t need double quotes.
the reason need them shell command shell parsing command line string, , uses them indication text run app.package.info -a com.package.name
should placed in single argument:
#!/usr/bin/env python import subprocess c_arg = 'run app.package.info -a com.package.name' command = ['/usr/bin/drozer', 'console', 'connect', '-c', c_arg] output = subprocess.check_output(command) print("got %r" % (output,))
when you’re using code start process, explicitly specify individual arguments, , no shell parsing going on, there’s no need quotes.
Comments
Post a Comment