First post here, I hope it is in the right place. I am new to Ruby,
and I am trying to write a simple cgi script.
I want to execute a method inside a cgi script, but I constantly get
the error:
[Sat Apr 12 12:49:39 2008] [error] [client 62.163.186.111] Premature end
of script headers: /Library/WebServer/CGI-Executables/biblio/main.rb
It doesn't matter if I just define the method locally in the script,
or if I create a class, and define the method there.
If I comment out the line: Person.new().saveNewPerson("bla",
"blabla"), the script properly returns the html with "Done"
If I copy the class and the command calling the class, and put them in
separate script (without cgi) and run that script, the "bla" and
"blabla" are written to the Person file as expected.
#!/usr/bin/ruby
class Person
def saveNewPerson(aFirstName, aLastName)
file = File.open("/Users/somePath/Person.xml", "r+")
file.puts(aFirstName)
file.puts(aLastName)
end
end
problem solved, it was a file permissions issue for the Person file. I
guess the webserver runs as a different user.
thanks anyway,
Rob
Yep. I was doing some tests, and I came to the same conclusion.
I guess we might as well post the solution for future searchers. To
write to a file from a cgi script,
1) The folder containing the file needs write and execute persmissions:
rwx-wx-wx. To change the permissions, first cd to the directory
containing the folder. Then issue the command: