[Tutor] is there an equivalent to the 'commands' module for Win32 platforms (95,98,NT)?

Karim Yaici karimy@nipltd.com
Mon, 21 May 2001 14:46:47 +0100


Another try with popen....
Because we a live in  a non-perfect world, I wanted to see what will happen
when you try to run a python script with 'os.popen' that is not valid.

First, I tried:
>>>print os.popen('python c:\\mydoc\\foo.py).read() #foo.py does not exist
BTW.
Here are the results:
-> With Python 2.0 (ActiveState version), I get nothing, empty string.
-> With Python 2.0 (on Linux), I get:
    python: can't open file 'foo.py'
-> With Python 1.5.2 (installed with Zope), I get:
C:\PROGRA~1\ZOPE\23~1.2\BIN\PYTHON.EXE: can't open file 'foo.py'

Next, I tried with a valid path but a non-valid code. So  'hellowin.py'
becomes:
-------------------------------
print "Windows sucks!" bla, bla
------------------------------

..which should raise NameError. However this does not work on ActivePython
(V2.0).

So, do I really need to a see a doctor, or you guys, know what it is all
about.

Cheers,
Karim
----- Original Message -----
From: "Karim Yaici" <karimy@nipltd.com>
To: "Remco Gerlich" <scarblac@pino.selwerd.nl>; <tutor@python.org>
Sent: Monday, May 21, 2001 12:45 PM
Subject: Re: [Tutor] is there an equivalent to the 'commands' module for
Win32 platforms (95,98,NT)?


> Thanks fot your help.
> It does actually work. Here is the synatx I used:
>
> ----hellowin.py----
> print "Windows sucks!"
> -----------------
>
> # To execute a command....
> >>> import os
> >>> os.system('python hellowin.py')
> Windows sucks!
> 0
> # I think that the zero is the status code -correct me if i'm wrong-,
which
> is always 0 in Windows
>
> # To capture the output...
> >>>output = os.popen('python hellowin.py').read()
> >>>output
> 'Windows sucks!'
>
> Cheers,
>
> Karim
> ----- Original Message -----
> From: "Remco Gerlich" <scarblac@pino.selwerd.nl>
> To: <tutor@python.org>
> Sent: Monday, May 21, 2001 11:56 AM
> Subject: Re: [Tutor] is there an equivalent to the 'commands' module for
> Win32 platforms (95,98,NT)?
>
>
> > On  0, Karim Yaici <karimy@nipltd.com> wrote:
> > > Hi there,
> > > I'd like to run some python scripts from another a script. I was
looking
> at
> > > the documentation this morning, and I found the 'command's module
which
> > > ,unfortunately, runs only on POSIX platforms. how can run commands in
a
> > > Win98 environment? Has anyone tried to do the same?
> >
> > The commands module is mostly just a wrapper around os.popen, as far as
I
> > know. You should be able to use os.system() to start a command, and
> > os.popen() to get output from the command. That last thing may be a bit
> > dodgy on Windows, I don't know about that.
> >
> > > There is also  a module called 'nt', no documentation available on
this
> one
> > > ;-(...I don't see any difference between this module and 'system', do
> you?
> >
> > You mean 'os'. 'nt' shouldn't be used directly, it's basically the same
as
> > 'os' - on Windows. 'os' is a wrapper around whatever platform-specific
> > module should be used.
> >
> > Try
> > >>> import os
> > >>> print os.name
> >
> > That should print 'nt' for you, meaning that the functions are taken
from
> > the nt module - on my Linux system, it print posix, taking its functions
> > from there.
> >
> > --
> > Remco Gerlich
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>