944,124 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 13945
  • Perl RSS
Jan 12th, 2007
0

Execute unix command from perl running on windows

Expand Post »
Hi friends,

I am using Perl Tk for a GUI application. It uses a telnet part wherin I need to login to a unix machine, execute a command and process the result.

The code is as follows :

my $result = $t->cmd(("grep - $filename.txt~ | wc -l | awk '{print $1}'"));

I am basically searching for '-" in the $filename.txt~.

The problem i am having is, the result always comes as 1 .. even thou the file does not contain any '-' symbol.
The command runs fine when used directly on unix.

Would appreciate if any one of you can help me out.

Regards,
Alex
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alex_wil is offline Offline
2 posts
since Jan 2007
Jan 12th, 2007
0

Re: Execute unix command from perl running on windows

maybe you need to use an array instead of a scalar for capturing the reults:

my @result = $t->cmd(("grep - $filename.txt~ | wc -l | awk '{print $1}'"));
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jan 15th, 2007
0

Re: Execute unix command from perl running on windows

Hi Kevin,

thanks for your reply. I did try as per what you told me too. but I still get no result.

Regards,
Alex


Click to Expand / Collapse  Quote originally posted by KevinADC ...
maybe you need to use an array instead of a scalar for capturing the reults:

my @result = $t->cmd(("grep - $filename.txt~ | wc -l | awk '{print $1}'"));
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alex_wil is offline Offline
2 posts
since Jan 2007
Jan 31st, 2007
0

Re: Execute unix command from perl running on windows

I'm very new to perl but you can try this
my @result = `grep - $filename.txt~ | wc -l | awk '{print $1}'"`;
that might work for you,
using the backtick which is the character under the tilda will run a system command and return the results back to your program.

Sorry if this doesn't work I"m very new at Perl.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mandible is offline Offline
7 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: perl JSP page calling from perl
Next Thread in Perl Forum Timeline: How to make matrix?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC