Re: running non-python progs from python

From: Spiffy (spiffy_at_worldnet.att.net)
Date: 12/09/03


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.
>



Relevant Pages

  • Re: Quando Apple lascia le cose al caso...
    ... " keep a backup file ... " make all windows the same size when adding/removing windows ... " remove '=' from the list of valid filename chars. ...
    (it.comp.macintosh)
  • Re: How to pass short filename in context menu?
    ... So in the command field in the registry change the path to cmd to something explorer can't find. ... Windows 95/98/Me: The Windows system directory. ... > would pass the long filename in a context menu shell command. ...
    (microsoft.public.windowsxp.general)
  • Re: running non-python progs from python
    ... Fredrik Lundh" wrote in message ... > that indicates that Windows cannot find the command, ... > (if the filename may contain spaces, you may have to add quotes around ... I DID NOT ASK ANYONE TO READ MY MIND, NOR DID I COMPLAIN THAT ANYONE COULD ...
    (comp.lang.python)
  • Re: del command and auto-named file disaster
    ... still have the original file "Copy of FILENAME". ... Hint: Delete command looked ... anything I can do e.g. a Windows tweak that allows Delete command to ... It is designed for users and has the safety net ...
    (microsoft.public.windows.file_system)
  • Re: running non-python progs from python
    ... > Fredrik, the example you provided is virtually the same as the one from the ... os.systemexecutes the command just as if you've typed ... Windows doesn't look at the Python path when you do ... (if the filename may contain spaces, you may have to add quotes around ...
    (comp.lang.python)