os.shell, recursion, encryption

Trent Mick trentm at ActiveState.com
Tue Feb 15 09:00:19 EST 2000


> > import os
> > zipExe = 'c:/progra~1/pkzipdos/pkzip.exe'
> > zipOutput = os.popen(zipExe + ' asdf.zip *.*', 'r')
> > print zipOutput.readlines()
>
> I gave this a shot.  I actually don't care about the return from pkzip,
> but I think this would work.  Unfortunately, an empty list is
> returned and
> there is no evidence that pkzip was ever executed.  Any ideas?
>
> > import os
> > zipExe = 'c:/progra~1/pkzipdos/pkzip.exe'
> > os.system(zipExe + ' asdf.zip *.*')
>
> I was using that one without the greater than sign, but I don't want to
> use the above because I'm walking through a directory tree and it would
> spawn too many windows that would all need to be closed.
>

You say, "would spawn too many windows". Do you mean that when you manually
run pkzip.exe from the command line it throws up a GUI interface? If that is
so that you can not automate it via any of the os.system() or os.popen()
commands in Python (or any scripting language). These functions are
providing an interface to a program with a command line interface (CLI),
with stdin, stdout, etc. They do not know how to talk to the GUI.

However, I thought that pkzip.exe was just a CLI and not a GUI.

Try the following. Open up a shell.

> cd "c:\program files\pkzipdos\pkzip.exe"
> pkzip
***SOME ERROR OR USAGE OUTPUT***
> python
>>> import os
>>> os.system('pkzip')
***SOME ERROR OR USAGE OUTPUT***


You should get the exact same result from 'pkzip' in the shell and
os.system('pkzip') in python intepreter.


Another thought. Are you on Win95/98? If so then I cannot really verify that
this stuff works. However, I *think* that os.system() works fine on Win9x
(although I wouldn't bet on it).


Trent





More information about the Python-list mailing list