I went through post after post on SO looking for a method to use quotation marks inside of arguments using subprocess.popen and I cannot seem to find a way.
This works fine from the commandline
runme.bat --include="check|check2" Python
#!/usr/bin/python import sys import subprocess import shlex #command_line = "./runme.sh --include=\"check|check2\"" command_line = "runme.bat --include=\"check|check2\"" arg = shlex.shlex(command_line) arg.quotes = '"' arg.whitespace_split = True arg.commenters = '' command_line_args = list(arg) print command_line_args command_line_process = subprocess.Popen( command_line_args, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) line = "" while True: line = command_line_process.stdout.readline() if line: print line break runme.bat
echo %* >> someargs.txt runme.sh
#!/bin/bash echo $@ I heard that subprocess.call() is a way around this but I'd like to be able to iterate line by line through the subprocess' output while the program is running.
Edit:
This seems to be a bug in Python because running runme.bat in cmd works correctly, running runme.py in linux works correctly, it's only when running runme.py on Windows where it doesn't work correctly. I created a ticket here.
Edit2:
It's not a python bug apparently lol. Look at chosen answer.
argsmight resolve the problem. Have you tried that already? If that doesn't work either, you might want to try filing that as a bug. Python should give you some way of passing an arbitrary command string without it trying to second-guess you.