simple cgi script issue

Thread Solved

Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

simple cgi script issue

 
0
  #1
May 27th, 2005
Hey there, i need some help with a simple cgi script.
i cannot get it to write output to a file.
here is the script.
  1. #!/usr/bin/python
  2.  
  3. import cgi
  4.  
  5. form = cgi.FieldStorage()
  6. Customer = form['Customer'].value
  7. Field = form['Field'].value
  8.  
  9. data = [Customer, Field]
  10.  
  11.  
  12. reshtml = """Content-Type: text/html\n
  13. <html>
  14. <head><title>Customer Data</title></head>
  15.  
  16. <body>
  17. <h1>Customer Data</h1>
  18. <p>Here ya go</p>
  19. </body>
  20. </html>"""
  21.  
  22.  
  23. print reshtml + 'Customer =' + data[0]
  24. print ' ' + ' Field = ' + data[1]
  25.  
  26. # this is where the script fails to do anything....
  27. OutFile = open("/home/nephish/Test.txt", "w")
  28. OutFile.write("Here is a spot of text to input")
  29. OutFile.close

it works, in that it returns the correct info to the browser,
but it does not write a text file.
i need to be able with this script to store on my disk what is input
in the html form.

any suggestions ?
Edit/Delete Message
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 918
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: simple cgi script issue

 
0
  #2
May 27th, 2005
I ran a quick test and on my Windows XP Box it seems to be the file path it balks at. I had to give it the full file path (or at least back to where python.exe sits)
  1. try:
  2. # needs full file path!
  3. OutFile = open("/home/nephish/Test.txt", "w")
  4. OutFile.write("Here is a spot of text to input")
  5. OutFile.close()
  6. print "File successfully written"
  7. except IOError:
  8. print "Cannot open file for writing"
Last edited by vegaseat; Aug 12th, 2009 at 12:49 pm.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

Re: simple cgi script issue

 
0
  #3
May 27th, 2005
OK, Here is what i got.
i got the correct text back when i submitted the form
then it printed out
"Cannot open file for writing"
i wonder if its a permissions issue, but i am running this from the user
'nephish' so perhaps its something else.

thanks, by the way.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 8
Reputation: ruwach is an unknown quantity at this point 
Solved Threads: 0
ruwach ruwach is offline Offline
Newbie Poster

Re: simple cgi script issue

 
0
  #4
May 27th, 2005
OH Hey, it was a permission problem.
i made a directory off root called /files and did a chmod 777 to it
rewrote the path to /files and ran it again and it worked this time.
thanks!

back in action....
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC