[Tutor] Commandline and backslash problem

nhytro-python@web.de nhytro-python@web.de
Sun, 28 Oct 2001 21:52:35 +0100

Quite right Roeland! I noticed this also 30mins ago, my application works =
"halfway" now. The wierdest, saddest thing is that switches don=B4t work wit=
h os.system():

### example
def howzat():
....prog =3D "C:\\blah.exe"
....switch =3D "-q"
....file =3D "aha.txt"
os.system("%s %s %s" %(prog, switch, file))
#### end example

the commandline application mentions "error, file not found-> -q" , appare=
ntly it thinks that the switch is a file, this is then skipped and it exec=
utes but without the switch.

Are switches built this way passed separately to the commandline=3F I took a=
 look at execl and spawnv, they did=B4nt work in my function, they just did =
not execute the commandline application :-(=20

Roeland Rengelink <r.b.rigilink@chello.nl> schrieb am 28.10.01:

Are you sure this is a backslash problem

I made this little testprogram, and as far as I can tell Entry.get() is
smart about escaping the backslashes.

from Tkinter import *

def ev(*args):
    t =3D e.get()
    print t, repr(t)

e =3D Entry()
b =3D Button(text=3D'do', command=3Dev)

Some example output
a\b 'a\\b'
a\b\\c\t\n 'a\\b\\\\c\\t\\n'

nhytro-python@web.de wrote:
> I have the "backslash" problem with an application I=B4m developing. I kno=
w about escaping forward slashes or using raw strings, but things are not =
working as I expect. A code snippet:
> #################code -start

What do you get if you replace go=5Frender with:

def go=5Frender():
    textfile =3D inputfile.get()
    print textfile
    editor =3D editorpath.get()
    print editor
    os.system("%s %s" % (editor, textfile))

As far as I can tell there's no need to do the string replacement

Hope this helps,



"Half of what I say is nonsense. Unfortunately I don't know which half"

Lotto online tippen! Egal zu welcher Zeit, egal von welchem Ort.
Mit dem WEB.DE Lottoservice. http://tippen2.web.de/=3Fx=3D13