New to Perl - strange behaviour with backticks

E

Eric

I am trying to set up a CGI script that will run two other scripts and
then write a short message back to the webpage. I have this mostly
working, except for one strange issue: after using backticks to read
the stdout from the first script, stdout from the second script is
being printed to the page as if it were printed from the CGI script
that acts as the caller. The behaviour disappears if I comment out
the backticks, but then I can't get the information i need from the
stdout of the first script. The code follows:

#!/usr/bin/perl
use CGI;

print "Content-type: text/html\n\n";
my $query = new CGI;
my $pdbCode = $query->param("pdbcode");
my $scriptPath = "~/Sites/etaserver/bin";
my $rankPath = "~/Documents/Templates/Distance\ Matcher/Data/2006/
Data";
my $pdbPath = "~/Documents/Templates/Distance\ Matcher/Data/
2006/2006pdb90\ ET/$pdbCode";
my $pymolPath = "/sw/lib/pymol-py24/bin/pymol";

my $extractMotifArgs = "perl -I$scriptPath \"$scriptPath/
extractmotif.pl\" \"$pdbPath/$pdbCode.clusters\" \"$pdbPath/
$pdbCode.dssp\" \"$pdbPath/$pdbCode.pdb\" \"$pdbPath/$p
my $motifs = `$extractMotifArgs`;
#my $motifs="1,2,3,4";

if($pdbCode =~ /^\d\w{3}\w?$/ && -e $pdbPath) {
$pdbPath =~ s/\\//g;
my $args = ("$pymolPath -cr $scriptPath/createPyMolImage.py --
$pdbCode \"$pdbPath\" $motifs");
system($args);
if (($? >> 8) == 0) {
print "CreatedImage:".$pdbCode;
} else {
print "Error:Unable to Create image";
}
} else {
print "Error:Unable to find PDB Data\n";
}

This is Perl 5.8.6.

Thank you,
Eric
 
G

Gunnar Hjalmarsson

Eric said:
I am trying to set up a CGI script that will run two other scripts and
then write a short message back to the webpage. I have this mostly
working, except for one strange issue: after using backticks to read
the stdout from the first script, stdout from the second script is
being printed to the page as if it were printed from the CGI script
that acts as the caller. The behaviour disappears if I comment out
the backticks, but then I can't get the information i need from the
stdout of the first script.

Assuming that

system($args);

executes the second script you are talking about, what if you call also
that script using backticks (in void context):

qx($args);

<code snipped>
 
X

xhoster

Eric said:
I am trying to set up a CGI script that will run two other scripts and
then write a short message back to the webpage. I have this mostly
working, except for one strange issue: after using backticks to read
the stdout from the first script, stdout from the second script is
being printed to the page as if it were printed from the CGI script
that acts as the caller.

The second time you invoke an external command, you do it with
"system". That is the way system works--it writes its output to the
stdout it inherits from Perl.
The behaviour disappears if I comment out
the backticks,

That seems unlikely. Perhaps when you comment out the backticks, the
system($args) no longer produces any output at all because it is not
passed anything interesting as its argument.

#!/usr/bin/perl
use CGI;

print "Content-type: text/html\n\n";
my $query = new CGI;
my $pdbCode = $query->param("pdbcode");
my $scriptPath = "~/Sites/etaserver/bin";
my $rankPath = "~/Documents/Templates/Distance\ Matcher/Data/2006/
Data";
my $pdbPath = "~/Documents/Templates/Distance\ Matcher/Data/
2006/2006pdb90\ ET/$pdbCode";
my $pymolPath = "/sw/lib/pymol-py24/bin/pymol";

my $extractMotifArgs = "perl -I$scriptPath \"$scriptPath/
extractmotif.pl\" \"$pdbPath/$pdbCode.clusters\" \"$pdbPath/
$pdbCode.dssp\" \"$pdbPath/$pdbCode.pdb\" \"$pdbPath/$p
my $motifs = `$extractMotifArgs`;
#my $motifs="1,2,3,4";

Both for purposes of posting here, and for purposes of your own debugging,
you should probably replace the external commands with calls to
simple commonly available system utilities, like echo or cat. That will
help you isolate the problem to the perl-specific part versus the
external part, and help us help you because we would be able to test
your code ourselves.

my $motifs=`echo 1,2,3,4`;


Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top