-1

I have a perl file which in turn calls another perl file. I am expecting output from second perl file. How would I get the output ? Here is what my sample code looks like.

datetimetest.pl

!/usr/bin/perl
use DateTime;
print DateTime->now()->strftime("%a, %d %b %Y %H:%M:%S %z");
print "\n";

my @perloutput = `/usr/bin/perl knowusername.pl`;
print "output:$perloutput[0]\n";
print "output 2: $perloutput[1]\n";

print "output 3: $perloutput[2]\n";

knowusername.pl

#!/usr/bin/perl
print $ENV{"LOGNAME"}."\n";

print "secondoutput\n";

print "thirdoutput\n";

I have edited answer above.

tech_enthusiast
  • 683
  • 3
  • 12
  • 37
  • Take a look at this question: http://stackoverflow.com/questions/364842/how-do-i-run-a-perl-script-from-within-a-perl-script – arkascha May 30 '13 at 08:24
  • @arkascha , how does that link help in my question ? I want to have output from one file to another file. – tech_enthusiast May 30 '13 at 08:27
  • Sorry, did you even bother to _read_ the first answer in that question? It is about script output to stdout and how to capture it. – arkascha May 30 '13 at 08:28
  • You're missing the `#` in your shebang line. Most likely a copy-paste error. Otherwise, this works for me. – chrsblck May 30 '13 at 08:31
  • @arkascha, I did look at the first answer, but my question is how do I pass output ? The answer shows how to capture them, not to pass them. – tech_enthusiast May 30 '13 at 08:34
  • Ok guys, I resolved my problem. The only thing which I needed to add was "\n" at all print functions in knowusername.pl. Thanks all. – tech_enthusiast May 30 '13 at 08:41

1 Answers1

1

First of all, always use use warnings; use strict;

Which would have caught your main issue here.

$output should be $perloutput

print "output:$perloutput[0]\n";
print "output 2: $output[1]\n";

print "output 3: $output[2]\n";
chrsblck
  • 3,948
  • 2
  • 17
  • 20