Thanks for your reply. Honestly, I'm not sure why the external method is 
skipped. I've tried several methods to debug and changed my python code to see 
the effects.

I wrote another Java Jar. called test.jar that when executed prints out a line 
to stdout and creates a text file to the same directory that the jar is placed 
in. I placed this jar file as well as the external method python file in the 
Extensions directory /var/lib/zope2.8/instance/plone-site/Extensions 

This is how the external method looks like:

def runYahooSearch2(self):

        import os

        homedir = os.getcwd()
        # on my machine homedir is /var/lib/zope2.8/instance/plone-site
        command = "java -jar "+ homedir + "/Extensions/test.jar"
        whatisread = os.popen(command).read()
        print whatisread

This external method is triggered in my DTML code. I've created other external 
before so i know i've done it right.. but the os.system() command for java -jar 
doesn't seem to work. I've tried to use other commands such as "ls" which works 

        command = "ls"
        whatisread = os.popen(command).read()
        print whatisread

This will sucessfully list out all the files/folders in the working directory.

Its just this java -jar which does not execute at all... I know it doesn't 
execute at all
cos it doesn't output a file or print the string. If i manually type out into 
the terminal

         java -jar /var/lib/zope2.8/instance/plone-site/Extensions/test.jar

it works perfectly, it prints out the string as well as outputs a text file 
into the directory the jar file is in.
But using the external method given above just gives me a blank output.

I've also tried popen2:

        from popen2 import popen2
        outputTGT, inputTGT = popen2(command)
        print outputTGT.readline()

and still the jar is simply skipped and not executed.

Is there any other method i can use instead of os.popen os.popen2 and os.system 
to run this command line
statement?... or any way i can catch the exception which is being thrown when 
the java
-jar is attempting to run ( if there is any in the firt place) ? Maybe this 
would help  in the debugging process.

Thanks in advance!



> -----Original Message-----
> Sent: Mon, 12 Feb 2007 21:24:24 +0100
> Subject: Re: [Zope-dev] Extrenal method unable to run the os.popen() or
> os.system() commands
> Ridzwan Aminuddin wrote at 2007-2-9 17:53 -0800:
> >Oh yes, i forgot to mention that in my code i did use the absolute paths
> to my java .jar file as you can see i my code below, the absolute path to
> the Extensions directory is in the variable homedir. I also set my
> classpath to point to the folder just in case..
> Relative paths do work -- but, they are (as always) relative to
> the current working directory.
> And unless you (or some buggy extension) have changed it, the
> current working directory will be Zope's instance home.
>> ...
> >homedir = os.getcwd()
> >homedir = homedir + "/Extensions"
> >command = "cd "+homedir
> >os.popen(command)
> The "popen" above still has no effect. You should remove
> code without effect as it clutters the source.
> >command = "java -jar "+ '"' + homedir + "/" + "ActiveLearningTools.jar"
> + '" ' +
> >"prepArticles >> test.txt"
> >os.popen(command)
> This will look for "ActiveLearningTools.jar" in
> "<instancehome>/Extensions". But the output file "test.txt"
> will be put into "<instancehome>" (as this name is still relative).
> Have you already told us in what way your "ExternalMethod" fails?
> Do you get an exception? Or is simply the output file not produced?
> Or does the output file remain empty?
> --
> Dieter

KEEP SPYWARE OFF YOUR COMPUTER - Protect your computer with Spyware Terminator!
Visit http://www.spywareterminator.com/install and find out more!
Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to