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 ,

@cmd= `find . -name "abc"`;
print "@cmd\n";

now what happens is, once the command completed then it will send entire output to @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
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to