什么是python 2.3 for windows执行像ghostscript这样的程序在路径中有多个参数和空格的最佳方法?

Set*_*ori 3 python windows ghostscript

当然有某种抽象可以实现这一点吗?

这基本上就是命令

cmd = self._ghostscriptPath + 'gswin32c -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4 
      -r196X204 -sPAPERSIZE=a4 -sOutputFile="' + tifDest + " " + pdfSource + '"'

os.popen(cmd)
Run Code Online (Sandbox Code Playgroud)

这种方式看起来真的很脏,必须有一些pythonic方式

Flo*_*sch 5

,它superseeds os.popen,虽然它不是更抽象的:

from subprocess import Popen, PIPE
output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]

#this is how I'd mangle the arguments together
output = Popen([
    self._ghostscriptPath, 
   'gswin32c',
   '-q',
   '-dNOPAUSE',
   '-dBATCH',
   '-sDEVICE=tiffg4',
   '-r196X204',
   '-sPAPERSIZE=a4',
   '-sOutputFile="%s %s"' % (tifDest, pdfSource),
], stdout=PIPE).communicate()[0]
Run Code Online (Sandbox Code Playgroud)

如果你只有没有子进程模块的python 2.3,你仍然可以使用os.popen

os.popen(' '.join([
    self._ghostscriptPath, 
   'gswin32c',
   '-q',
   '-dNOPAUSE',
   '-dBATCH',
   '-sDEVICE=tiffg4',
   '-r196X204',
   '-sPAPERSIZE=a4',
   '-sOutputFile="%s %s"' % (tifDest, pdfSource),
]))
Run Code Online (Sandbox Code Playgroud)