![]() |
Problem with executing UNIX command in perl script
Hi All,
I am trying to execute a complex piped UNIX command in perl script as follows: system("nm @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB " {print $8 " " $3}'| grep '^[^$]' | uniq | sort -r | awk '$1 != prevvar {varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' | sort > $ofname"); and it fails with many errors. The errors are compile time errors and more problems than that. awk uses $0,$1 and I noticed that perl may substitute its own values for $1.... I tried to get information from PERL documentation and it says that if I pass entire command and argument list as single scalar (which I am doing), if there are any shell metacharacters (there are in current case) it is passed to shell for parsing. Hence it should be able to execute this. Any pointers to documentation which can give me more insight into this or any help will be greatly appreciated. Thanks, Sunil. |
Re: Problem with executing UNIX command in perl script
On Wed, 24 Dec 2003 17:47:36 -0800, sunil wrote:
> Hi All, > I am trying to execute a complex piped UNIX command in perl > script as follows: > > system("nm @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB " {print $8 " " > $3}'| grep '^[^$]' | uniq | sort -r | awk '$1 != prevvar > {varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' | sort > > $ofname"); > > and it fails with many errors. The errors are compile time errors and more > problems than that. awk uses $0,$1 and I noticed that perl may substitute > its own values for $1.... > I tried to get information from PERL documentation and it says that if I > pass entire command and argument list as single scalar (which I am doing), > if there are any shell metacharacters (there are in current case) it is > passed to shell for parsing. Hence it should be able to execute this. > Any pointers to documentation which can give me more insight into this or > any help will be greatly appreciated. Thanks, > Sunil. You are using a literal " character in a "-delimited string, for one. Also note that using a "-delimited string will interpolate Perl variables typed in the string literal. To combat all of this use something like (untested): system q[m @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB " {print $8 " " $3}'| grep '^[^$]' | uniq | sort -r | awk '$1 != prevvar {varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' | sort > $ofname]; where the q[ ... ] construct is equivalent to ' ... ' (that is, uninterpolated string), but doesn't get confused by your use of ' characters in the string literal. look for qq and q in "perldoc perlop" for more info. HTH -- Joost Diepenmaat There are rot13's in my address. Remove them and apply one to mail me. |
Re: Problem with executing UNIX command in perl script
"sunil" <sunilsreenivas2001@yahoo.com> wrote in message news:d924fa71.0312241747.6583b441@posting.google.c om... > Hi All, > I am trying to execute a complex piped UNIX command in perl > script as follows: > > system("nm @ARGV | awk -F\| '$4 == "OBJT " && $5 == "GLOB " {print $8 > " " $3}'| grep '^[^$]' | uniq | sort -r | awk '$1 != prevvar > {varstr=sprintf("char %s[%d];",$1,$2);print varstr;prevvar = $1}' | > sort > $ofname"); Why not use Perl to process the output from nm? Otherwise, you'd be better off just writing it as a shell/awk script. |
| All times are GMT. The time now is 07:25 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.