If I read your post correctly, you're basically wanting to issue a system command from Perl and read the output of that command back into Perl. Based on that, I personally would go with what I consider in my mind to be the "quick and dirty" method, which is to use back ticks to issue the command.
In my sample code below, I'm storing a command in $cmd and then using back ticks issue that command and store the output in $cmd_out.
use strict;
my $cmd = 'cat /proc/cpuinfo';
my $cmd_out = `$cmd`;
There's a few things to keep in mind with this method:
- Your Perl script will wait until the system command is complete before continuing.
- This only gives you STDOUT. If there's an error message sent to STDERR, that output is not captured.
- I believe that the issued command only has the same level rights as the user account used to run the Perl script.
I'm not advocating that this is the best route to go, but it usually gets the job done for this lazy programmer. :D
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.