Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: How to print called program to stdout

by pryrt (Abbot)
on Mar 19, 2016 at 00:06 UTC ( [id://1158295]=note: print w/replies, xml ) Need Help??


in reply to Re: How to print called program to stdout
in thread How to print called program to stdout

There are some details that would help make it easier to answer your questions. 1) What is the form of the output from your subprograms? (ie, Do they print to STDOUT or STDERR, or do they just return a value?). 2) How are you calling the subprograms from your main program? (ie, as direct function/method calls, or by system() calls or qx// or ``).

Because if your subprograms are just printing to STDOUT, and you are calling them from your main program via function/method calls, it surprises me that you cannot see their output. But if you are calling a separate process (which your use of "program" rather than "function" or "method" might indicate) using a system() call, then you are going to have to switch to a print `subprogram` paradigm, otherwise the separate process's output will be lost to the system()'s ether.

Update: Specifically, if your mainprogram.pl looks like:

#!perl use warnings; use strict; use MyModuleToBeTested; callSomeFunctionThatPrintsToSTDOUT();
... then i don't see why it wouldn't print.

OTOH,

#!perl use warnings; use strict;
system("callSomeProgram");
print `runASecondProgram`;
... will not print anything from "callSomeProgram", because system() doesn't output, whereas it will print the STDOUT from "runASecondProgram" because of your print statement.

edit: strikeout patently false info and fix typos from the fix. Thanks choroba

Replies are listed 'Best First'.
Re^3: How to print called program to stdout
by choroba (Cardinal) on Mar 19, 2016 at 09:49 UTC
    > because system() doesn't output

    It does. system prints to STDOUT, you just can't access its output from the calling Perl program:

    $ perl -we 'system "date"' Sat Mar 19 10:48:46 CET 2016
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      oops, you're right (struck out)

      What I really should have been pointing out is that without the print statement, `` or qx// wouldn't output anything.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1158295]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found