Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird Failure after System() call

Status
Not open for further replies.

fox12

Programmer
Jan 18, 2005
62
0
0
US
I have a test.cgi program which calls a perl program by using system(). I have the code snippet like below:

print STDERR "Before Executing Cmd\n";
system($cmd);
print STDERR "Cmd complete\n";

$cmd is a .pl program which will create a three files in the specified directory.

In the log file, I can find the entry "Before Executing Cmd". And, in the specified directory, all of the three files were successfully created. However, the test.cgi return 500 Internal Server Error in the web browser. What's more weird is that "Cmd complete" was never entered into the error log file. Instead, there is an entry saying "Premature end of script header".

any Guru here can help me resolve this?

Thanks a ton in advance.
 
You need to print an http header if running as a CGI:

Code:
print "Content-type: text/html\n\n";
print STDERR "Before Executing Cmd\n";
system($cmd);
print STDERR "Cmd complete\n";
print "Complete";

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
It still failed, even if I did that. In addition, since I am writing to the error log, it should succeed in putting "Cmd complete" to the Apache error log file. But it did not go anywhere. Instead, it showed the msg "prematured end of script header". It worked on one VirtualHost ( but failed on another( Both site VirtualHost are identitical except the domain. Both run on the same Apache server.

And if there is an error, it should return an xml message. If succeeds, it will return an image.
 
The premature messages comes when you are sending HTML to the browser before sending a proper header. Maybe you should post some more code or try printing your headers farther up in your script.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
What is $cmd?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thank you very much, guys. I just figured out what it was a time-out issue.

By the way, there is none output before executing the system() command.

$cmd = "/some/path/to/test.pl >& /tmp/mylogs/logs.txt"

The test.pl will read data from a ftp server and db, and create three xml files. All files are created. It turns out that some data is too big, and takes long time to finish to update the xml file properly. Hence, the web server just time out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top