CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [FishMonger] Storing the output of perl command in a file: Edit Log


Nov 29, 2014, 10:11 AM

Views: 13628
Re: [FishMonger] Storing the output of perl command in a file

I have tried my code as a non-cgi program. Its working fine.

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

##right now just compile the code for the client

$ClientCode = "print 'ABCDE\n' print 'abcde' print '12345' ";
#storing the code in file

my $dirstr = 'D:/Zulfi/dir1';

$fileName = $dirstr . "/";

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);

Also I found a documeion from:

which says the same thing which you [FishMonger]told me last time:


#-- scalar context
$result = `command arg1 arg2`;

#-- the same command in list context
@result = `command arg2 arg2`;

Notice that the only output captured is STDOUT, to collect messages sent to STDERR you should redirect STDERR to STDOUT

I would try to change the logic & do the explicit redirection as you showed.


(This post was edited by zak100 on Nov 29, 2014, 10:17 AM)

Edit Log:
Post edited by zak100 (User) on Nov 29, 2014, 10:17 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives