I have a simple batch file here which will print a word document from the command line.
"C:\Program Files\Microsoft Office\Office12\winword.exe" "p:\docs\daily checks.doc" /mFilePrintDefault /mFileExit
I am trying to place this into a python script, I have managed to get the document to open by using
subprocess.Popen('"C:\\Program Files\Microsoft Office\Office12\winword.exe"' '"P:\\docs\\daily checks.doc "')
I can’t seem to get the /mFilePrintDefault /mFileExit part in the command, I have tried using +'"/mFilePrintDefault /mFileExit"' plus without the +, but then the document won’t open.
Can you possibly help to see how I can print this word document, or is there a better way
Thanks in advance
This should work:
Or, altenatively,
When you use
shell=Truethe command is executed through a shell. This means that you have to pass a single string the same way as you would write the command in a shell, that is, with the quotes to prevent arguments with spaces to be splitted.When you use
shell=False(the default value), the command isn’t executed through a shell. This means that you’ve to split the arguments yourself. The way you do this, is passing a list with all the arguments. In this case, no extra quoting is needed because the list elements already provide this information.