您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Windows上的python 2.3最好的方法是执行具有多个参数和路径中空格的ghostscript之类的程序吗?

Windows上的python 2.3最好的方法是执行具有多个参数和路径中空格的ghostscript之类的程序吗?

使用子进程,它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]

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

os.popen(' '.join([
    self._ghostscriptPath, 
   'gswin32c',
   '-q',
   '-dNOPAUSE',
   '-dBATCH',
   '-sDEVICE=tiffg4',
   '-r196X204',
   '-sPAPERSIZE=a4',
   '-sOutputFile="%s %s"' % (tifDest, pdfSource),
]))
python 2022/1/1 18:32:41 有210人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶