[Tutor] [Fwd: [Python-Help] Dos command line]

Karim Yaici karimy@nipltd.com
Fri, 1 Jun 2001 09:44:16 +0100


Steve,
I usually use popen to run DOS commands.  In the following, I'll try to run
a Python script and capture the output:

import os
script_path = "c:\\python\\mydoc\\test_popen.py"
operating_system = os.name
if operating_system == 'nt': # yeah! you may not need this check, but I
prefer to use the 'commands' module for
#  *nix
  fd = os.popen('python %s'%script_path)
 outtext = fd.read()
 fd.close()

The same thing if you want to run other commands (dir, cd...).
Keep in mind that if  you are running python 1.52, according to the docs,
this method is unreliable(it does not seem to work on IDE's). I think this
has been fixed in 2.0 (& 2.1). Last thing, if your script (test_popen.py)
contains any errors then the output will be empty under Windows( correct me
if I am wrong , guys:-) )

Cheers,

Karim


----- Original Message -----
From: "steve tran" <steve.tran@nts-inc.com>
To: <tutor@python.org>
Sent: Thursday, May 31, 2001 12:53 AM
Subject: [Tutor] [Fwd: [Python-Help] Dos command line]


> Hi,
>
> Can I have an example for os.open to run dos comand line or batch file?
>
> thanks,
>
> Steve
>