print output on console at runtime
--0-1078255183-1310535975=:41973
Content-Type: text/plain; charset=us-ascii
hi,
i need to print the output of a command on the console at runtime
lets say, i need to execute find command .as of now , what i am doing is ,
[at] cmd= `find . -name "abc"`;
print " [at] cmd\n";
now what happens is, once the command completed then it will send entire output to [at] cmd
and then entire output gets printed to console in one shot
instead of that , i need output to be printed as it progresses
plz suggest
regards
irfan
--0-1078255183-1310535975=:41973--
Re: print output on console at runtime
--20cf300fb095b2405b04a7ed5399
Content-Type: text/plain; charset=ISO-8859-1
You can use system command inside perl
system(" find . -iname 'abc'");
--
Shekar
On Wed, Jul 13, 2011 at 11:16 AM, Irfan Sayed <irfan_sayed2002 [at] yahoo.com>wrote:
> hi,
>
> i need to print the output of a command on the console at runtime
> lets say, i need to execute find command .as of now , what i am doing is ,
>
> [at] cmd= `find . -name "abc"`;
> print " [at] cmd\n";
>
> now what happens is, once the command completed then it will send entire
> output to [at] cmd
> and then entire output gets printed to console in one shot
>
> instead of that , i need output to be printed as it progresses
>
>
> plz suggest
>
>
> regards
> irfan
--20cf300fb095b2405b04a7ed5399--
Re: print output on console at runtime
At 10:46 PM -0700 7/12/11, Irfan Sayed wrote:
>hi,
>
>i need to print the output of a command on the console at runtime
>lets say, i need to execute find command .as of now , what i am doing is ,
>
> [at] cmd= `find . -name "abc"`;
>print " [at] cmd\n";
>
>now what happens is, once the command completed then it will send
>entire output to [at] cmd
>and then entire output gets printed to console in one shot
>
>instead of that , i need output to be printed as it progresses
You have two choices that I can think of:
1. Use the Perl module File::Find instead of forking an external
process to run the operating system's find command.
See 'perldoc File::Find'.
Example (untested):
use File::Find;
find( sub{
return unless $_ eq 'abc';
print qq($File::Find::name\n)
}, q(.)
);
2. Fork the find program using open and a mode parameter of '-|'
instead of back-quotes.
See 'perldoc -f open'.
Example (untested):
open( my $find, '-|', q(find . -name "abc")) or die("Can't fork find
program: $!");
while( <$find> ) {
print;
}
--
Jim Gibson
Jim [at] Gibson.org
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: print output on console at runtime
Irfan Sayed wrote:
> hi,
Hello,
> i need to print the output of a command on the console at runtime
> lets say, i need to execute find command .as of now , what i am doing is ,
>
> [at] cmd= `find . -name "abc"`;
> print " [at] cmd\n";
>
> now what happens is, once the command completed then it will send entire output to [at] cmd
> and then entire output gets printed to console in one shot
>
> instead of that , i need output to be printed as it progresses
open my $PIPE, '-|', 'find', ',', '-name', 'abc' or die "Cannot open
pipe from 'find' because: $!:
while ( <$PIPE> ) {
print;
}
close $PIPE or warn $! ? "Error closing 'find' pipe: $!"
: "Exit status $? from 'find'";
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: print output on console at runtime
--0-1621167944-1310542072=:9844
Content-Type: text/plain; charset=us-ascii
thanks John and Jim
but, is this solution is applicable to only "find" command ?
if i change the command to some other system command , will this solution work?
plz suggest
________________________________
From: Jim Gibson <jimsgibson [at] gmail.com>
To: Perl Beginners <beginners [at] perl.org>
Sent: Wednesday, July 13, 2011 12:00 PM
Subject: Re: print output on console at runtime
You chose to allow Jim Gibson (jimsgibson [at] gmail.com) even though this message failed authentication
Click to disallow
--0-1621167944-1310542072=:9844--
Re: print output on console at runtime
At 12:27 AM -0700 7/13/11, Irfan Sayed wrote:
>thanks John and Jim
>but, is this solution is applicable to only "find" command ?
No.
>if i change the command to some other system command , will this
>solution work?
Yes.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: print output on console at runtime
--0-1377588390-1311835005=:31544
Content-Type: text/plain; charset=us-ascii
can this be happen if command needs to be executed on remote machine and the output needs to be forked on the local console at runtime
please suggest
regards
irfan
________________________________
From: Jim Gibson <jimsgibson [at] gmail.com>
To: Perl Beginners <beginners [at] perl.org>
Sent: Wednesday, July 13, 2011 12:00 PM
Subject: Re: print output on console at runtime
You chose to allow Jim Gibson (jimsgibson [at] gmail.com) even though this message failed authentication
Click to disallow
--0-1377588390-1311835005=:31544--
Re: print output on console at runtime
--0-1030871890-1311861948=:59848
Content-Type: text/plain; charset=us-ascii
further,
i am executing following command using open
open $frk, "devenv /rebuild release ReusableU.sln /useenv 2>&1 |" or die "Couldn't execute program: $!";
now i need to capture the exit status of this command
i tried with $? but it does not contain the exit status
please suggest
regards
irfan
________________________________
From: Irfan Sayed <irfan_sayed2002 [at] yahoo.com>
To: Jim Gibson <jimsgibson [at] gmail.com>; Perl Beginners <beginners [at] perl.org>
Sent: Thursday, July 28, 2011 12:06 PM
Subject: Re: print output on console at runtime
can this be happen if command needs to be executed on remote machine and the output needs to be forked on the local console at runtime
please suggest
regards
irfan
________________________________
From: Jim Gibson <jimsgibson [at] gmail.com>
To: Perl Beginners <beginners [at] perl.org>
Sent: Wednesday, July 13, 2011 12:00 PM
Subject: Re: print output on console at runtime
You chose to allow Jim Gibson (jimsgibson [at] gmail.com) even though this message failed authentication
Click to disallow
--0-1030871890-1311861948=:59848--