logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Problem with storing error of a perl command in afile
Author
zak100



Joined: 15 Nov 2013
Posts: 1
Location: Pakistan, Karachi

PostPosted: Fri 28 Nov '14 17:44    Post subject: Problem with storing error of a perl command in afile Reply with quote

Hi,
I am trying to store the output of perl command and the error generated during compiling the code in a file. I can store the output of command but i am getting error in storing its error. My code is :
Code:

#!C:/Perl64/bin/perl.exe
 
 
use DBI;
use CGI;
use CGI::Session;
use Path::Class;
 
my $existingdir;
my $cgi;
my $dirstr;
my $filename;
my $TextMessage;
 
$cgi = new CGI;
 
##for creating a unique file for each client we have to do session management
##right now just compile the code for the client
 
$ClientCode = $cgi->param ('ClientCode') || '';
#storing the code in file
 
 
my $dirstr = 'D:/Zulfi/dir1';
 
 
$fileName = $dirstr . "/filetest1.pl";
 
mkdir $dirstr unless -d $existingdir; # Check if dir exists. If not create it.
 
 
open (MYFILE, ">$fileName")or die "Can't open '$fileName'\n";
print MYFILE $ClientCode;
 close (MYFILE); 
 
open (MYFILE, ">TestFile") || die "\n   Could not create write file.\n\n";
print MYFILE `perl $fileName 2>&1`;
close (MYFILE);
 
open(MYFILE,  "<TestFile")     or die "Unable to open file, ";
 
my @entire_file=<MYFILE>; #Slurp!
close (MYFILE);
 
print "Content-type: text/html\n\n";
print <<EOF;
<HTML>
<HEAD>
<TITLE> Coding Page </TITLE>
</Head>
<BODY>
<textarea name="ProjectCode" rows="5" cols="60">
 
</textarea></p>
<form method="post" action="compile.pl">
 
<p>Client Code: 
<textarea name="ClientCode" rows="5" cols="60">
EOF
print $ClientCode;
 
 
print <<EOF;
</textarea>
 
</p>
 
 
<p><input type="submit" name="compile" value="compile"></p>
 
</form>
<textarea name="Output_Error" rows="5" cols="60">
EOF
print @entire_file;
print <<EOF;
</textarea></p>
</BODY></HTML>   
 
EOF
exit;

Its storing the output of command in TestFile. But if i give error type code in code window like:

print qqqqqqqqqqqq

then it will not store the error message in the TestFile.
The program consists of 3 windows (text areas). I would write code in the client window (middle one). If compile button is pressed, then it would store the output or error in the output_error window (bottom one). Right now its only storing output of commands like if i write following in client window:
print "AAAAA";
print "BBBBB";
Then the output would store in output_error window but if there is a error as in th example below:

kkkkkkkkkkkkkkkk

then it will not store the error message of perl in the output window. Please guide me.

Zulfi.
Back to top
philwill22



Joined: 01 Dec 2014
Posts: 1
Location: usa, tulsa

PostPosted: Mon 01 Dec '14 17:17    Post subject: Re: Problem with storing error of a perl command in afile Reply with quote

Your code is very poor, but it seems like you aren't redirecting things correctly. Not much idea what you're talking about with the different windows, and you're referencing scripts you don't post here...not sure what's to be said without correct information.

How long have you been working with Perl, and where did you get that code?
Back to top


Reply to topic   Topic: Problem with storing error of a perl command in afile View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner