5

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?

Wayne Werner
  • 45,646
  • 26
  • 189
  • 275

1 Answers1

5

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.

nneonneo
  • 162,933
  • 34
  • 285
  • 360
  • 1
    Yes, the problem isn't the escaping (that's only for displaying the string, after all), it's the quotes. – kindall Jan 31 '13 at 18:24