Sublime Forum

[Windows] Issue with " (double quote) in subprocess.Popen

#1

Hello,

I can’t figure out how to send a string with double quote in a simple cmd command on Windows.

Here is my code :

params = [r"C:\Windows\System32\cmd.exe", 'echo "test"']
print(subprocess.list2cmdline(params))
p = subprocess.Popen(subprocess.list2cmdline(params))

In the console , it returns :

C:\Windows\System32\cmd.exe “echo “test””

Escaping the quotes with " returns the same result :

C:\Windows\System32\cmd.exe “echo “test””

Any idea ?

I tried everything =)

0 Likes

#2

Did you try:

p = subprocess.Popen(["echo", "test"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print(p.communicate()[0].decode('utf-8'))
1 Like