Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Script outputs on screen

by atu (Novice)
on Oct 24, 2013 at 16:47 UTC ( [id://1059517]=perlquestion: print w/replies, xml ) Need Help??

atu has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I have a question:

I am running two scripts lets assume they are named script1 and script2.

In a solaris machine i am running script1 with a few arguments and it is calling script2 with information derivered from these:

Script1: { ....do stuff. `script2 a b c`; ... do more stuff }

and script2 has something like that:

Script2: { ....do stuff. print a lot of information about some tables in the database, update them, drop them and so on. ... do more stuff }

now if i run script2 from unix terminal it will spam screen with information related to tables on the database, print a lot of traces such as;

Working on table1: changing A to B: dropping table2: table dropped:

and so on, it keeps doing that for may be 4-5 minutes and prints a few lines on the terminal for every few seconds.

I want it to still do this when i call it from script1 but when i just use `script2 a b c`; screen looks like it is frozen, when i check DB i can see it is changing the tables but there are no traces on it.

When i call it as following from script1:

my $string = `script2 a b c`; print "\n $string \n";

This time screen again looks frozen and after script2's work is done (about 4-5 mins later) it suddenly prints all the info at onece, and thats bad, how can i call it so that string2 is outputting the traces on the screen but not the $string variable?

Replies are listed 'Best First'.
Re: Script outputs on screen
by toolic (Bishop) on Oct 24, 2013 at 16:54 UTC
      Oh thanks, didn't know that
Re: Script outputs on screen
by oiskuu (Hermit) on Oct 24, 2013 at 17:52 UTC
    The `` slurps all output before it returns. Read from a file handle instead.
    open( my $fh, '-|', "script2 a b c" ) or die; while (<$fh>) { print; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-23 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found