如何在Windows上使用Python 2.3以多个参数和路径中有空格的方式执行类似ghostscript的程序?

2024-09-30 20:29:11 发布

您现在位置:Python中文网/ 问答频道 /正文

当然,有某种抽象的东西允许这样做吗?在

这基本上就是命令

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

os.popen(cmd)

我觉得这条路很脏,一定有Python的路


Tags: 命令selfcmda4dnopausedbatchsdevicesoutputfile
1条回答
网友
1楼 · 发布于 2024-09-30 20:29:11

使用subprocess,它将超过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]

如果只有python2.3没有子进程模块,那么仍然可以使用os.popen公司在

^{pr2}$

相关问题 更多 >