views:

511

answers:

2

Surely there is some kind of abstraction that allows for this?

This is essentially the command

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

os.popen(cmd)

this way looks really dirty to me, there must be some pythonic way

+2  A: 

Use subprocess, it superseeds os.popen, though it is not much more of an abstraction:

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]

If you have only python 2.3 which has no subprocess module, you can still use os.popen

os.popen(' '.join([
    self._ghostscriptPath, 
   'gswin32c',
   '-q',
   '-dNOPAUSE',
   '-dBATCH',
   '-sDEVICE=tiffg4',
   '-r196X204',
   '-sPAPERSIZE=a4',
   '-sOutputFile="%s %s"' % (tifDest, pdfSource),
]))
Florian Bösch
A: 

Okay I got an interesting one.

from subprocess import Popen, PIPE ImportError: No module named subprocess

Im using python 2.3 AS this script needs to run from here C:\OpenOffice_24\program\ which is in the open office environment.

I presume that subprocess is not supported in win python 2.3

Is there another way around?

Setori
This is part of your question -- it is NOT an answer.
S.Lott