2

I am running a perl script over ssh like the below:

[dipuh@local ~]$ ssh dipuh@myremote_001 'perl /home/dipuh/a.pl'

The content of a.pl is the below:

print "Sleeping \n";
sleep(60);
print "Waking Up";

Here my local terminal waits for the perl script to execute completely and once finished displays the complete output. The initial "Sleeping" text also will be printed only with the final output.

Is there any way, in my local terminal, I can display the output of each command in the perl script at the run time, instead of waiting for the whole perl script to finish.

2 Answers 2

4

You are suffering from buffering.

You may either set $| to 1 for the block.

{
    local $| = 1;
    print "Sleeping \n";
    sleep(60);
    print "Waking Up";
}

Or use IO::Handle

use IO::Handle;
STDOUT->autoflush(1);
Sign up to request clarification or add additional context in comments.

Comments

2

You can try to turn the autoflush mode on. The old fashioned way to it is by adding the following at the top of your script:

$| = 1;

or you can do it with the more modern way:

use IO::Handle;

STDOUT->autoflush(1);

Alternatively, you can flush the STDOUT on demand with:

use IO::Handle;

print "Sleeping \n";
STDOUT->flush;
sleep(60);
print "Waking Up";
STDOUT->flush;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.