Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Dell PowerEdge Servers
  #1  
Old July 15th, 1999, 05:12 PM
thai
Guest
Dev Shed Newbie (0 - 499 posts)
 
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";}


Reply With Quote
  #2  
Old July 23rd, 1999, 04:15 AM
jamesh
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
What you want to ensure is that the file is being written to a world writable directory.When the file is written, it will be owned by the web server user (typically 'nobody').


Try ...
open(MY_TEMP_FILE, ">/tmp/temp.out") | |
die "Can't open file for writing; $!n";

You may also need to give the browser an idea of what it is expected to do by sending it a content header before any other output. You can do this simply by 'print "Content-type: text/htmlnn";', or by using the perl module CGI call 'header'. The two newline statements are important, without them the script will fail.

The system call that you are using may also have to be fully qualified, depending on your system set-up.

#!/usr/bin/perl

# listdir.pl
# prints the local directory

# get the local directory
my $directory = `ls`;

# the directory string will contain newlines.
# use this convenience to split the string into array elements
my @file_array = split("n", $directory);

# print a header
# using a simple approach here as we don't need CGI
# features for a simple script (nor overhead).
print "Content-type: text/htmlnn";

# recurse through the array and print each array element to
# STDOUT, in this case, a web page
foreach $file (@file_array) {
print "<P>$file</P>n";
}

Dont forget to chmod +x the script first.

or, using shell

#!/bin/sh
echo "Content-type: text/html"
ls

James

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > capture and display output on the web


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway