Seite 1 von 1

os.system und/oder os.spawnv Problem mit Argumenten in Win.

Verfasst: Samstag 16. August 2008, 12:44
von chrisko
Hallo,

ich hab ein unschönes Problem mit den Befehlen os.system und/oder os.spawnv. Ich würde gerne für mein Programm DXF2GCODE (sieh google) eine art Filter einbauen um PDF oder PS Dateien einzulesen. Hierzu würde ich gerne aus Python mit Hilfe des Programms pstoedit eine dxf erstellen lassen welche ich dann bei mir importieren kann.
Leider hat Windows Probleme mit den Pfadangaben und ich krieg es einfach nicht hin. Das Problem ist bereits mehrmals umschrieben und hier auch gleich die LINKS dazu:
http://starship.python.net/pipermail/py ... 01035.html
http://effbot.org/librarybook/os.htm

Aus dem ganzen hab ich mir mal ein Testscript zusammengebaut.

Code: Alles auswählen

# File: os-spawn-example-3.py

import os
import string

if os.name in ("nt", "dos"):
    exefile = ".exe"
else:
    exefile = ""

def spawn(program, *args):
    try:
        # check if the os module provides a shortcut
        return os.spawnvp(program, (program,) + args)
    except AttributeError:
        pass
    try:
        spawnv = os.spawnv
    except AttributeError:
        
        # assume it's unix
        pid = os.fork()
        
        if not pid:
            os.execvp(program, (program,) + args)
        return os.wait()[0]
    else:
        # got spawnv but no spawnp: go look for an executable
        for path in string.split(os.environ["PATH"], os.pathsep):
            file = os.path.join(path, program) + exefile
            try:
                print  file
                return spawnv(os.P_WAIT, file, (file,) + args)
            except os.error:
                pass
        raise IOError, "cannot find executable"

#
# try it out!

spawn("C:\Program Files (x86)\pstoedit\pstoedit",\
      '-f dxf', r'"C:\pstoedit_test.pdf"', r'"C:\print.dxf"')

print "goodbye"
Ich hoffe irgendjemand kann mir sagen was hier schief läuft oder was es noch für Möglichkeiten gibt das Programm mit den gewünschten Optionen aus Python heraus auszuführen. Eine Beispiel DXF zum import ist hier zu finden:
http://www.vegasoft.de/shares/svn/dxf2g ... t_test.pdf

Vielen Dank
Gruß
Christian :?

Verfasst: Samstag 16. August 2008, 13:43
von lunar
subprocess nutzen.

Verfasst: Sonntag 17. August 2008, 18:43
von chrisko
vielen Dank,

mit Subprocess gings ohne Probleme.

Gruß
Chirstian