Re: running non-python progs from python
From: Spiffy (spiffy_at_worldnet.att.net)
Date: 12/09/03
- Next message: Uwe Grauer: "Re: Reading and writing Mozilla-mail in python"
- Previous message: Jacek Generowicz: "Re: Speed: bytecode vz C API calls"
- In reply to: Fredrik Lundh: "Re: running non-python progs from python"
- Next in thread: Michel Claveau/Hamster: "Re: running non-python progs from python"
- Reply: Michel Claveau/Hamster: "Re: running non-python progs from python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Dec 2003 21:49:39 GMT
"Fredrik Lundh" <fredrik@pythonware.com> wrote in message
news:mailman.261.1070970251.16879.python-list@python.org...
> "Spiffy" wrote:
>
> > > How can I run this other program from a python script and pass the
> > filename
> > > as a parameter?
> >
> > import os
> >
> > filename = "myfile"
> > os.system("program %s" % filename)
> >
> > </F>
> >
> > Fredrik, the example you provided is virtually the same as the one from
the
> > "Learning Python" book.
>
> that indicates that it's supposed to work, don't you think?
IT COULD HAVE BEEN A MISPRINT, DON'T YOU THINK?
> > When I run it, the dos command line appears with the message 'Bad
command
> > or file name".
>
> that indicates that Windows cannot find the command, don't you think?
>
> > Both the .exe and the .mid file are in the python path and the spelling
has
> > been checked.
>
> you mean sys.path?
IF I HAD MEANT sys.path, I WOULD HAVE SAID sys.path, DON'T YOU THINK?
that's the problem, most likely. As mentioned in the
> documentation, os.system() executes the command just as if you've typed
> it in a "DOS box". Windows doesn't look at the Python path when you do
> that, so to make sure Windows finds the command, you have to add it to
> the Windows path (the PATH environment variable), or provide the full path
> to os.system().
>
> program = r"x:\full\path\to\program"
> filename = "..."
> os.system("%s %s" % (program, filename))
>
> the os.path.abspath() function can be useful in cases like this; it makes
sure
> that if your program can find a file, another program can also find it:
>
> program = os.path.abspath("x:/somewhere/program")
> filename = os.path.abspath("somefile")
> os.system("%s %s" % (program, filename))
>
> (if the filename may contain spaces, you may have to add quotes around
> the second %s)
TYPING THE FULL PATH GIVES ME THE SAME RESULT: NOTHING. THE ABOVE CODE USING
os.path.abspath CAUSES A DOS BOX TO APPEAR AND DO NOTHING WHILE PYTHON
CRASHES.
> the relevant manual page contains more information on os.system, and
> mentions a couple of alternatives (os.startfile, os.spawnlp, etc):
>
> §http://www.python.org/doc/current/lib/os-process.html
>
> > Pardon me for being a newbie, but if you don't have an answer, why do
you
> > have to give me attitude?
>
> os.system() is still the answer; the problem is in how you used it and
what
> you expected from it, not in the function itself. You cannot expect
people
> to read your mind, and then complain when they fail.
I DID NOT ASK ANYONE TO READ MY MIND, NOR DID I COMPLAIN THAT ANYONE COULD
NOT READ MY MIND.
I DO NOT THINK THE PROBLEM IS IN HOW I USED THE FUNCTION NOR WHAT I EXPECTED
FROM IT.
>
- Next message: Uwe Grauer: "Re: Reading and writing Mozilla-mail in python"
- Previous message: Jacek Generowicz: "Re: Speed: bytecode vz C API calls"
- In reply to: Fredrik Lundh: "Re: running non-python progs from python"
- Next in thread: Michel Claveau/Hamster: "Re: running non-python progs from python"
- Reply: Michel Claveau/Hamster: "Re: running non-python progs from python"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|