Problems running stand-alone python .exe from jython

kcollins15 at cfl.rr.com kcollins15 at cfl.rr.com
Tue Dec 10 13:41:03 EST 2002


HELP>>>>I concede, I really don’t know what else to do. My dilemma……  I need to 
unzip from jython.  The zip file is quite large with a directory structure. 
(the zip file is apache 2.0.39)  My jython unzip.py is not handling the write 
or read well; I’m doing something wrong with the input and output stream, I 
gave up. 
****jython unzip.py*********
#open the zipped file and extract the content 
zf =zipfile.ZipFile("C:\\temp\\apache-2_0_39-windows.zip", "r")
if hasattr(zf, 'namelist'):
     files = zf.namelist()     
     #print files
     for name in files:          	    
          if os.path.isdir(name):	 
               newFile = open ('C:/'+name, "wb")
               print newFile
               newFile.write (zf.read (name))
               newFile.close()           
          else:               
               mdir = 'C:/'+name
               print "Making Directory", mdir 
               os.makedirs(mdir) 
else:     
     print "Zip File is empty"

So I created a python module that works wonderfully.  Pretty much the same code 
as above. Because I am deploying to users and do not want to install python I 
created a standalone unzip.exe.  Run this by itself, it works great.  My 
problem is when I execute from jython the process does not finish, it just 
hangs about half way through reading and write the files over the targetDir..  
I’m not handling the 'process' correctly but I don’t know what to do.  
fileName is zip file
targetDir is target directory
cmd_string is ../unzip.exe
*************code to run exe***************
from java.lang import Runtime, Process
from java.io import BufferedReader, InputStreamReader

def system(cmd_string, fileName, targetDir):
      proc = java.lang.Runtime.getRuntime().exec(cmd_string + " " + fileName 
+ " " + targetDir)     
      proc.waitFor()      
      if (proc.exitValue() == 0):
             brIn = BufferedReader(InputStreamReader(proc.getInputStream
()))      
             return brIn
      else:
             brErr = BufferedReader(InputStreamReader(proc.getInputStream()))
             error = brErr.readLine()
             brErr.close()
             print error
             proc.destroy()
             return FALSE

Any suggestions on either the jython unzip or the jython calling the python 
unzip.exe would be very helpful.
Thanks,
kc








More information about the Python-list mailing list