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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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



zak100
User

Nov 29, 2014, 10:11 AM


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

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

Code
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 = "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;
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:
http://www.perlhowto.com/executing_external_commands

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



Quote
Example:

#-- 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.

Zulfi.


(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