passing double quotes in subprocess

Larry Martell larry.martell at gmail.com
Tue Sep 8 13:11:12 CEST 2015


On Tue, Sep 8, 2015 at 7:03 AM, loial <jldunn2000 at gmail.com> wrote:
> I need to execute an external shell script via subprocess on Linux.
>
> One of the parameters needs to be passed inside double quotes
>
> But the double quotes do not appear to be passed to the script
>
> I am using :
>
> myscript = '/home/john/myscript'
> commandline = myscript + ' ' + '\"Hello\"'
>
> process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> output,err = process.communicate()
>
>
> if I make the call from another shell script and escape the double quotes it works fine, but not when I use python and subprocess.
>
> I have googled this but cannot find a solution...is there one?

Try it with 2 backslashes:

commandline = myscript + ' ' + '\\"Hello\\"'


More information about the Python-list mailing list