On Wed, Apr 20, 2016 at 11:57 PM, loial <jldunn2...@gmail.com> wrote: > I am trying to run lpr from python 2.7.10 on windows > > However I always get the error > 'C:/windows/system32/lpr.exe ' is not recognized as an internal or external > command, > operable program or batch file. > > Even though typing the same at the command prompt works OK > > > Any ideas? > > I am using subprocess as follows > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > where command line is > C:/windows/system32/lpr.exe -S 172.28.84.38 -P RAW C:/john/myfile
You''re running that through the shell, which means you have to abide by shell rules. I don't have a Windows handy, but I'm pretty sure its shell isn't happy with forward slashes in the command line; I might be wrong there. My recommendation: Split that into separate arguments, pass them as a list, and remove shell=True. And unless you need to be completely explicit for some reason (eg to protect against path-based exploits), cut the first argument to just "lpr" and let the binary be found anywhere. ChrisA -- https://mail.python.org/mailman/listinfo/python-list