[Zope-dev] Extrenal method unable to run the os.popen() or
os.system() commands
Ridzwan Aminuddin
wanster at inbox.com
Fri Feb 9 03:47:09 EST 2007
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
If the command line executables had run this error would not occur as one of the jar files was supposed to output a text file called output.txt.
I tried running this script, modified on its own off the terminal using "python test.py" and it works perfectly... but once DTML calls this script it is unable to run the cammand line portion...
can anyone please help me out or point me in the right direction...
Thanks and regards
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
More information about the Zope-Dev
mailing list