Help running Windows programs from Python

Mensanator mensanator at aol.com
Fri May 7 16:07:01 EDT 2010


On May 7, 2:14 pm, Scott <scott.freem... at gmail.com> wrote:
> I want to write a script to automate log archiving/compressing on a
> Win2003 server. I have Python 2.6 installed. I am planning to use 7-
> zip for compression (because I have been using it manually for a while
> now). For now all operations will be local in the C: drive.
>
> As a total beginner I'm having trouble grasping the control of
> external programs.
>
> I have found these options but have not tried any yet - I would like
> some advice on which approach would be the most appropriate to begin
> with.
>
> Command Line Application Approach:
> os.system
> os.spawn*
> os.popen*
> popen2.*
> commands.*
> All of the above recommend replacing with subprocess module
> subprocess - latest way to do command line?
> pexpect module -http://sourceforge.net/projects/pexpect/, Most recent
> file is dated 1/5/2008
>     It should work on any platform that supports the standard Python
> pty  module. (Windows?)
>         pty - "On Windows, only sockets are supported; on Unix, all
> file descriptors." (gulp, ??)
>
> COM Application Approach:
> Per the 7-zip FAQ: Use the 7z.dll or 7za.dll - I haven't found these
> files yet on sf.net.
> comtypes 0.6.2 - has the word COM in it?
> pywin32 / win32com  - there's that word again.
>
> And then there is this whole idea of "wrappers."
>
> Thanks,
> Scott

Here's a simple example:

>>> import os
>>> the_output = os.popen("dir "+"c:\\python31\\user\\*.py").readlines()
>>> for i in the_output:print(i,end='')

 Volume in drive C has no label.
 Volume Serial Number is 06DE-55B4

 Directory of c:\python31\user

09/08/2009  01:38 PM               689 3435.py
11/10/2009  06:43 PM               614 4697.py
03/09/2010  08:42 PM             5,922 5x.py
03/30/2010  07:51 PM             1,937 7[18] impure.py
08/28/2009  08:43 PM             1,867 bones.py
05/05/2010  07:21 PM               441 code.py
03/22/2010  04:31 PM               639 collatz_curiosity.py
09/18/2009  08:06 PM            17,125 collatz_game.py
08/20/2009  03:09 PM               406 csv_file_fix__minimal_2_all.py
11/06/2009  08:18 PM               432 digitsets.py
07/20/2009  07:03 PM            14,451 gmpy_geni_test_3.py
10/23/2009  05:35 PM             2,952 hit_target.py
03/19/2010  07:52 PM               245 how_many_random.py
04/15/2010  07:06 PM               217 issquare.py
07/31/2009  05:14 PM             1,132 itune.py
07/31/2009  04:41 PM               527 itune_stats.py
10/08/2009  08:08 PM             6,202 make_numbers.py
04/14/2010  08:00 PM               354 montyhall4.py
04/21/2010  07:46 PM             1,196 Ryan_Whited.py
03/25/2010  07:53 PM             4,318 ultimate_cycle.py
              20 File(s)         61,666 bytes
               0 Dir(s)  102,634,008,576 bytes free
>>>



More information about the Python-list mailing list