LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-29-2004, 04:23 PM   #1
larsenmtl
LQ Newbie
 
Registered: Feb 2004
Posts: 23

Rep: Reputation: 15
Python CGI - Batching in R


Hey all,

I have an apache web-server running a python CGI. The idea is that the user enters R code (a statistical language - http://www.r-project.com), the python CGI writes this to a text file, batches that file using the R executable, and then reads the R output from another file.

Everything runs with no error, however, although the CGI writes the R code to the batching file, when it is batched it's like an empty file! The code that was written to it is ignored.

I'm running the apache server as user www all batching and output files are stored in /home/www

Any ideas? The code follows:

Code:
#!/usr/bin/python

import cgi
import cgitb; cgitb.enable()    # Turn on CGI debugging info
from os import system, getcwd

# HTTP headers
print 'Status: 200 OK'
print 'Content-type: text/html'
print

# HTML head
print '''<html><head><title>Test R Batch CGI</title></head><body>'''

# Get the form fields, if any
form = cgi.FieldStorage()

if not form.has_key("data"):
	# No form data means this is the first access; output the form
	print '''<FORM METHOD="POST" action="rexecute">
	Type your data here: <input name=data value="" type=text><br>
	<input type=submit value="Submit"><br>
	</FORM>'''
else:
	RCommands = form.getvalue('data')
	RFile = "/home/www/R.r"
	f = file(RFile, 'w')
	f.write(RCommands)
	f.close
	command = "R CMD BATCH /home/www/R.r /home/www/r.rout"
	system(command)
	ROutFile = "/home/www/r.rout"
        f = file(ROutFile, 'r')
	print(f.read())
	f.close()

# HTML end
print '</body></html>'
Thanks.

Last edited by larsenmtl; 09-29-2004 at 04:25 PM.
 
Old 09-29-2004, 04:24 PM   #2
larsenmtl
LQ Newbie
 
Registered: Feb 2004
Posts: 23

Original Poster
Rep: Reputation: 15
Ahh crap the http for the r language shoule be http://www.r-project.org
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python CGI script can't write files, permission denied The_Nerd Programming 4 03-17-2005 12:19 PM
how to configure apache in Suse 9.1 t run cgi programmes written in python drako123 Linux - Software 0 08-21-2004 07:27 AM
CGI in Python indian Programming 2 08-18-2004 02:32 PM
problem apache2 CGI python MoinMoin (wiki) brasschaat Linux - Software 1 08-11-2004 08:26 AM
bizarre python behavior - simple cgi variables SerfurJ Programming 2 04-14-2004 02:58 PM


All times are GMT -5. The time now is 04:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration