On Wed, Apr 15, 2009 at 10:41, John W. Krahn <jwkr...@shaw.ca> wrote: > Chas. Owens wrote: >> >> On Wed, Apr 15, 2009 at 09:20, Rajini Naidu <rajinid...@gmail.com> wrote: >>> >>> I am trying to execute the below line in the perl program and returns a >>> value 0. >>> >>> my $test2 = ""; >>> my $include = "file"; >>> >>> $test2 = system("/usr/atria/bin/cleartool desc \$include | grep created | >>> awk -F\" \" \'{print \$2}\' | cut -b 1-9 "); >>> >>> The value returned by $test2 is 0. I suspect grep and awk commands are >>> not >>> getting executed. >>> Is there any thing wrong in the syntax ???? >> >> The system[1] function returns 0 on success and a nonzero value >> specific to the operating system on failure (often the programs >> exit code and the value returned by exec[2]). You could use the >> qx// operator[3] to capture the STDOUT of the command: >> >> my $test2 = qx{/usr/atria/bin/cleartool desc \$include | >> grep created | awk -F\" \" \'{print \$2}\' | cut -b 1-9}; >> >> but a much safer and faster way is to use the open[4] function >> and avoid using external programs like grep and awk: >> >> open my $pipe, "-|", "/usr/atria/bin/cleartool", "desc", $include >> or die "could not run cleartool: $!"; >> >> my @matches; >> while (<$pipe>) { >> next unless /created/; >> my @rec = split; >> push @matches, substr $rec[1], 0, 9; >> } > > Don't forget to verify that the pipe also closed correctly: > > close OUTPUT or warn $! ? "Error closing /usr/atria/bin/cleartool pipe: $!" > : "Exit status $? from /usr/atria/bin/cleartool"; snip
If that is going to match the example it should be close $pipe or warn $! ? "Error closing /usr/atria/bin/cleartool pipe: $!" : "Exit status $? from /usr/atria/bin/cleartool"; -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/