
July 15th, 1999, 05:12 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Hi,
I'm trying to capture some output from executing a command and then print this output. The problem is that executing this perl script on the command line works
but it doesn't work from the web. I tried a whole bunch of ways. Could someone clue me in on how to make this thing work? Does it have something to do with having permission to create the files?:
Thanks.
(cmd.pl just prints out hello world)
print "####################################################<BR>n";
print "Attempt 1: Capture info using pipe command<BR>n";
open(PIPE, "cmd.pl >script |");
while (<PIPE> ) {
push @stuff, $_;
}
close (PIPE);
while (@stuff) {
$it = shift(@stuff);
print "$it";
}
print "Results of pipe command should be in the file...so check file<BR>n";
open(THEFILE, "script") | | print "Could not open script<BR>n";
@stuff = <THEFILE>;
foreach $line (@stuff) {
print "$linen";
}
close(THEFILE);
print "####################################################<BR>n";
print "Attempt 2: Capture info using backticks<BR>n";
@stuff = `cmd.pl`;
open(MYFILE, ">script1") | | print "Could not open script1 for writing<BR>n";
foreach $line (@stuff) {
print MYFILE "$line";
}
close(MYFILE);
print "Results of backticks command should be in the file...so check file<BR>n";
open(MYFILE, "script1") | | print "Could not open script1 for reading<BR>n";
@array = <MYFILE>;
foreach $line (@array) { print "$line";} close(MYFILE);
print "####################################################<BR>n";
print "Attempt 3: Capture info using pipe(w/out '> script' this time)<BR>n";
open(SYSCALL, "cmd.pl |");
while (<SYSCALL> ) {
push @output, $_;
}
close (SYSCALL);
print "Open the file to write the info to...<BR>n";
open(MYFILE, ">script2") | | print "Could not open script2 for writing<BR>n";
while (@output) {
$oneline = shift(@output);
print "$oneline";
print MYFILE "$oneline";
}
close(MYFILE);
print "Results of pipe command should be in the file...so check file<BR>n";
open(MYFILE, "script2") | | print "Could not open script2 for reading<BR>n";
@array = <MYFILE>;
foreach $line (@array) { print "$line";} close(MYFILE);
print "####################################################<BR>n";
print "Attempt 4: Capture info using system command<BR>n";
system("cmd.pl > script3");
print "Results of system command should be in the file...so check file<BR>n";
open(THEFILE, "script3") | | print "COULD NOT OPEN THE script3 FILE<BR>n";
@array = <THEFILE>;
foreach $line (@array) { print "$line";}
|