Nov 29, 2014, 10:11 AM
Re: [FishMonger] Storing the output of perl command in a file
I have tried my code as a non-cgi program. Its working fine.
$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 . "/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;
open (MYFILE, ">TestFile") || die "\n Could not create write file.\n\n";
print MYFILE `perl $fileName 2>&1`;
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)