From: Jamie C. <jca...@we...> - 2001-11-16 12:00:57
|
NONAKA Akira wrote: > > Hi, > > I am trying to write my webmin module and have a question about perl > programming. > > I have a test.cgi like below. > > $ cat test.cgi > > #!/usr/bin/perl > print "Content-type: text/html; Charset=iso-8859-1\n\n"; > > $| = 1; > print "foo<br>"; > system("echo bar"); > print "baz<br>"; > > If I run this script from shell, I works fine. But if run this script from > my web browser through Webmin, perl system() function will fail with > errno=13 and "bar" is not echoed. > > If I change this test.cgi script like > > system("echo bar > /dev/null"); > > system() will return 0. > > I seems to me that I cannot use stdout in the script called from system() > under miniserv.pl. > > Q1. Is this a bug? > > Q2. Are there any work around? I want to write something to stdout in the > script called from system(). Unfortunately , the script is not written in > perl. The problem here is that when webmin's webserver runs a perl script (like one of the cgi programs), it captures and redirects STDOUT in perl so that it can be parsed for perl headers and so on. This works fine for all IO done in perl (print statements and the like), but if your perl script runs another program that outputs stuff, it will not work. The solution is to do : print "foo<br>\n"; open(OUT, "echo bar |"); while(<OUT>) { print; } close(OUT); print "baz<br>"; - Jamie |