Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell subprocess to stop escaping my quotes?

I'm trying to call Vim using subprocess, and pass it an argument. For example:

subprocess.call(['gvim.exe', ''' "+map <F5> :echo 'Hello!'<cr>" '''])

This command works on the command line:

> gvim.exe "+map <F5> :echo 'Hello!'<cr>"

And then I hit F5 and it tells me hello.

The subprocess call doesn't work. When I look at the process in task manager, I see that my string is now:

"\" +map <F5> :echo 'Hello!'<cr>\""

Not at all what I expected, and I don't think it's what Vim expects, either. It looks like subprocess is somehow escaping my quotes, but I don't know why.

Is there any way I can get this to work like I expect?

like image 673
Wayne Werner Avatar asked Jan 31 '13 18:01

Wayne Werner


1 Answers

The quotes aren't necessary since subprocess.call passes the arguments directly to the process without using the shell (unless you set shell=True).

So, subprocess.call(['gvim.exe', "+map <F5> :echo 'Hello!'<cr>"]) will suffice.

like image 126
nneonneo Avatar answered Sep 24 '22 17:09

nneonneo