> -----Original Message-----
> From: [EMAIL PROTECTED]
> Sent: Fri, 09 Feb 2007 09:51:37 +0100
> To: [EMAIL PROTECTED], zope-dev@zope.org
> Subject: Re: [Zope-dev] Extrenal method unable to run the os.popen() or
> os.system() commands
> 
> 
> 
> --On 9. Februar 2007 00:47:09 -0800 Ridzwan Aminuddin <[EMAIL PROTECTED]>
> wrote:
> 
>> Hi guys...
>> 
>> I wrote an external python script which would grab some HTML and so some
>> text and file preprocessing.
>> 
>> The script then is supposed to run come command line methods... using
>> os.system() .. however when i run the script triggered by my DTML code
>> it
>> manages to do the grabbing of the html and saving it into a file ans
>> stuff... but once it hits the portion where its supposed to run the
>> command lines.. it just skips everything and goes right to the end....
>> after which this error message is shown :
>> 
>>  Error Type
>>     IOError
>> Error Value
>>     [Errno 2] No such file or directory:
>> '/var/lib/zope2.8/instance/plone-site/Extensions/output.txt' Request
>> made
>> at
>> 
> 
> You can resolve this issue on your own by checking why the file is
> generated in the wrong place or by it is looked up at the wrong
> place..adding some debug code or using pdb should be sufficient to track
> this down.
> 
> -aj



Hi AJ!

Sorry about that, i will revert to the users list.

The problem with the script is that it does not execute the os.system() 
commands at all,
not that it generates the file at the wrong place or anything.

Do you know why this happens and how i can remedy it?

I seem to have found an old thread of someone facing the same problem but the 
suggestion
solution is not appropriate for my case. I have even made sure that the 
CLASSPATHS have
been set to the directory holding my .jar file

http://mail.zope.org/pipermail/zope-dev/2003-June/019918.html


Thanks again!

wan




Here is my code :




def removeIllegalChars( tgtString ):

        import os
        import sys
        from yahoo.search.news import NewsSearch
        import re

        tgtString = re.sub('<([^!>]([^>]|\n)*)>', '', tgtString)
        tgtString = re.sub('<([^>]([^>]|\n)*)>', '', tgtString)
        tgtString = re.sub('\n', '', tgtString)
        tgtString = re.sub('\t', '', tgtString)
        tgtString = re.sub('\r', '', tgtString)
        tgtString = re.sub('  ', '', tgtString)

        if tgtString:
                try:
                        tgtString = str(tgtString)
                except UnicodeEncodeError:
                        tgtString = str(tgtString.encode('U8'))

        return tgtString


def getYahooAPI():

        import os
        import sys
        from yahoo.search.news import NewsSearch
        import re

        queryWord = "Singapore"

        print ("Fetching data from YahooAPI with query : " + queryWord  )
        srch = NewsSearch('YahooDemo',query = "Singapore asean cup", language = 
'en', results = 50)
        info = srch.parse_results()
        info.total_results_available

        homedir = os.getcwd()
        tgtFile = homedir + "/Extensions/InputString.txt"

        writeFile = open(tgtFile, 'w')

        for result in info.results:

                writeFile.write("<Article>\n")
                writeFile.write("<Title>\n")
                writeFile.write(removeIllegalChars(result['Title'])+ "\n")
                writeFile.write("<URL>\n")
                writeFile.write(removeIllegalChars(result['ClickUrl']) + "\n")
                writeFile.write("<Summary>\n")
                writeFile.write(removeIllegalChars(result['Summary']) + "\n")
                writeFile.write("<Date>\n")
                writeFile.write(removeIllegalChars(result['PublishDate']) + 
"\n")
                writeFile.write("<Source>\n")
                writeFile.write(removeIllegalChars(result['NewsSource']) + "\n")
                writeFile.write("<Body>\n")

                writeFile.write(removeIllegalChars(result['Summary']) + "\n")

        writeFile.write("<EndOfFile>")
        writeFile.close

def runYahooSearch2(self):

        import os
        import sys
        from yahoo.search.news import NewsSearch
        import re

        
#-----------------------------------------------------------------------------------------------------------

        # still trying to figure out how to get the absolute path to this script
        # commands below work for windows... but not for linux. Need to find a 
platform
        # independant one

        # print 'sys.argv[0] =', sys.argv[0]
        # homedir = os.path.dirname(sys.argv[0])   # for windows
        # print 'path =', pathname

        getYahooAPI()

        homedir = os.getcwd()
        homedir = homedir + "/Extensions"


        command = "cd "+homedir
        os.popen(command)

        command = "java -jar "+ '"' + homedir + "/" + "ActiveLearningTools.jar" 
+ '" ' + "prepArticles >> test.txt"
        os.popen(command)

        print "Completed step 1 : preparing the articles"

        command = homedir + "/" + "vcluster " + "-zscores " + "ClutoMatrix" + " 
2"
        sysCode = os.system(command)
        print "Completed step 2 : Clustering the articles using Cluto"


        command = "java -jar "+ '"' + homedir + "/" + "ActiveLearningTools.jar" 
+ '" ' + "processClusters >> output.txt"
        sysCode = os.system(command)

        filename = homedir +"/output.txt"
        openfile = open(filename, 'r')
        whatisread = openfile.read()
        openfile.close()
        #os.remove("output.txt")

        return whatisread
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to