LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-30-2012, 01:50 PM   #1
onyxdragun
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Rep: Reputation: Disabled
[perl] Reading output from a system cmd


This is what I have
Code:
#!/usr/bin/perl
system "cat /proc/net/arp  | awk 'NR > 1 {print \$4}'"
Which reads the MAC addresses from the ARP table.

What I would like to do is be able to pass that into an array so I can foreach() it to process the results line by line.

Now, print outputs to the screen. I thought about assigning the call to @macs or something but I don't think that is totally correct.
I was using exec before, but read that exec does not return, where as system will return.

So, am I on the right track or am I completely lost? lol
 
Old 04-30-2012, 01:54 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by onyxdragun View Post
This is what I have
Code:
#!/usr/bin/perl
system "cat /proc/net/arp  | awk 'NR > 1 {print \$4}'"
Which reads the MAC addresses from the ARP table.

What I would like to do is be able to pass that into an array so I can foreach() it to process the results line by line.

Now, print outputs to the screen. I thought about assigning the call to @macs or something but I don't think that is totally correct.
I was using exec before, but read that exec does not return, where as system will return.

So, am I on the right track or am I completely lost? lol

Start learning Perl properly. You do not need 'awk' if you write in Perl.

Regarding your particular question - look up 'perl backticks'.

Learn from http://perldoc.perl.org/ - see in the left column 'Manual' -> Overview ( http://perldoc.perl.org/index-overview.html ) and so forth.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue sg_modes cmd at cmd line, want to see the cmd in binary form NuUser Linux - Newbie 1 03-28-2012 08:08 AM
Output rpm cmd listing onto a CD? flasun Linux - Newbie 2 02-12-2009 06:57 AM
perl: send output of system() call to variable drkstr Programming 4 07-23-2006 10:47 PM
store output of cmd in array? h/w Programming 6 10-09-2003 08:46 PM
Awk and Shell CMD Output xanthium Programming 16 04-24-2002 06:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration