apache - Use bat file in CGI Python on localhost -


i'm quite stuck with complex mix of files , languages! problem: webform starts python script, cgi script, on localhost(apache). in python script want execute batchfile. batchfile executes several commands, tested thoroughly.

if execute following python file in python interpreter or in cmd execute bat file. when 'start' python script webform says did it, there no results, guess wrong cgi part of problem?!

the process complicated, if has better way of doing this...pls reply;). i'm using windows makes things more annoying sometimes.

i think it's not script, because try subprocess.call, os.startfile , os.system already! either nothing or webpage keeps loading(endless loop)

python script:

import os subprocess import popen, pipe import subprocess  print "content-type:text/html\r\n\r\n" p = subprocess.popen(["test.bat"], stdout = subprocess.pipe, stderr = subprocess.pipe) out, error = p.communicate() print out print "done!" 

the bat file:

@echo off ::preprocess datasets cmd /c java weka.filters.unsupervised.attribute.stringtowordvector -b -i data_new.arff -o data_new_std.arff -r tweetin.arff -s tweetin_std.arff :: make predictions incoming tweets cmd /c java weka.classifiers.functions.smo -t tweetin_std.arff -t data_new_std.arff -p 2 -c first > result.txt 

thanks reply!!

your bat file redirecting second program's output file, p.communicate can output of first program. i'm assuming want return content of result.txt?

i think should skip bat file , both java invocations in python. more control of execution , can check return codes, there might problems java not being in path environment variable when run cgi. following equivalent respect getting program's output back, want capture second program's output if webservice supposed return predictions.

import os import shlex subprocess import popen, pipe import subprocess  print "content-type:text/html\r\n\r\n" p = subprocess.popen(shlex.split("java weka.filters.unsupervised.attribute.stringtowordvector -b -i data_new.arff -o data_new_std.arff -r tweetin.arff -s tweetin_std.arff"),      stdout = subprocess.pipe, stderr = subprocess.pipe) out, error = p.communicate() return_code = subprocess.call(shlex.split("java weka.classifiers.functions.smo -t tweetin_std.arff -t data_new_std.arff -p 2 -c first > result.txt")) print out print "done!" 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -