os.system, backslash and commandline problem

Sharriff.Aina at med-iq.de Sharriff.Aina at med-iq.de
Tue Oct 30 08:44:06 EST 2001


I am trying to code a small frontend for a commandline application using
tkinter. Upon using os.system to call the commandline program with
switches, I noticed that the switches were detected as files and not passed
on, furthermore, passing paths on is somewhat problematic.

#### code snippet, callback function for tkinter button

def go_app():
........textfile = inputfile.get() # inputfile is a tkintet entry widget
........textfile = string.replace(textfile, '/', '\\')
........editor = editorpath.get()# editorpath is a tkinter entry widget
........editor = string.replace(editor, '/', '\\')
........editor = editor + " -test" # switch test
........os.system(r"%s %s" % (editor, textfile))
........
############## end code

I tried out a file that had "dangerous" characters:
c:\the\boy.txt ("\t" TAB, "\b" BELL)

the commandline application was correctly called but the file above caused
a "file not found" error. I did a print to screen and saw that the path was
trashed: " theoy.txt "

Is there no sure way to run commandline executables with switches with
os.sytem? also switches built into a command (example "c:\foo.exe -test")
always fail, with a file not found error.

This is very saddening, any clues? help?


Thanks in advance


Sharriff








More information about the Python-list mailing list