os.shell, recursion, encryption

Trent Mick trentm at ActiveState.com
Mon Feb 14 13:37:58 EST 2000


> Thanks for the lesson.  It's a little clearer, but now I question whether
> this can be used for what I want to do.  It seems like popen creates a
> file.  I don't want to do that.  Instead, I'd like to simply run a
> commercial program with a command like 'pkzip asdf.zip *.*'.  I gave the
> following a try and it came back with "bad command or filename."  Am I on
> the right path or should I be using a different function than popen?
> os.system() doesn't work and I don't know what mode to use for spawnv.
> Thanks again.
>
> import os
> zipExe='c:/progra~1/pkzipdos/pkzip.exe'
> os.popen('> '+zipExe+' asdf.zip *.*', 'w')

I have not been following this thread but methinks you want to say:

import os
zipExe = 'c:/progra~1/pkzipdos/pkzip.exe'
zipOutput = os.popen(zipExe + ' asdf.zip *.*', 'r')
print zipOutput.readlines()

The p in popen stand for 'pipe' I believe. You are openning a pipe to the
command that you are running (here pkzip). The 'bad command or filename' is
comming from the greater than sign '>' that you prefixed the command with. I
think you may be using the Perl syntax for open(). If you still get 'bad
command or filename' then pkzip.exe is not where you think it is or
something else is broken.

As well you want to open the pipe for reading because you want to get the
status output from pkzip (right?). If you don't care about the zip status
output then try

import os
zipExe = 'c:/progra~1/pkzipdos/pkzip.exe'
os.system(zipExe + ' asdf.zip *.*')

Again, when you say that os.system() was broken as well, I think the greater
than sign is your problem.

Hope this helps,

Trent






More information about the Python-list mailing list