Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Get output from system()

Reply
Thread Tools

Get output from system()

 
 
Perl Learner
Guest
Posts: n/a
 
      06-22-2005
hi there again

in my program, i am trying to check if gnuplot is installed on the
system

for that, i have been thinking of doing

system("which gnuplot")

and, depending on the output i get from it, find out whether or not it
is installed.

in linux, if the software isn't installed, the $status variable is set
to 1. but this isn't the same (atleast) on (these) Sun machines. so
now i can not rely on the $status variable.

so i want to take the output from the terminal and do some parsing.
but how do i get that output (when i do system("which gnuplot")) into
my perl program?

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      06-22-2005
"Perl Learner" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> in my program, i am trying to check if gnuplot is installed on the
> system
>
> for that, i have been thinking of doing
>
> system("which gnuplot")


....

> so i want to take the output from the terminal and do some parsing.
> but how do i get that output (when i do system("which gnuplot")) into
> my perl program?


It seems fairly obvious to me that if want to learn more about the
system function, then you check the documentation for the system
function:

perldoc -f system

You might want to consult the posting guidelines for this group to learn
how you can help yourself, and help others help you.

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      06-22-2005
Perl Learner <(E-Mail Removed)> wrote:


> hi there again



You need to learn to try searching the standard docs *before* asking
hundreds of people around the world to help you with your problem.


> how do i get that output (when i do system("which gnuplot")) into
> my perl program?



The way that the documentation for the function that you are
using says to:

perldoc -f system

This is not what you want to use to capture the output
from a command, for that you should use merely ...


Using a function without reading its docs is the programming
equivalent of signing a contract without reading it.

You are asking for trouble if you continue to sign without reading
the contract first.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      06-23-2005
Perl Learner wrote:
[...]
> system("which gnuplot")
>

[...]
> but how do i get that output (when i do system("which gnuplot")) into
> my perl program?


Exactly the way it is described in the FAQ ('perldoc -q system', 'perldoc -q
output'):
"Why can't I get the output of a command with system()?"
and exactly the way it has been explained in this NG over and over again
and exactly as it is defined in the documentation of the very function you
are using ('perldoc -f system'; paragraph 3, sentence 3).

jue


 
Reply With Quote
 
Perl Learner
Guest
Posts: n/a
 
      06-23-2005
i did look at

perldoc -f system

and i didn't understand what they meant by "backticks" (although, it
now seems fairly obvious from the name itself. i didn't know what they
meant by that when i first read it and i hence posted the question
here)

anyway, i am posting the solution here so someone would find it useful
in the future


$terminaloutput = `whoami`;
print "you are $terminaloutput";

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      06-23-2005
Please quote an appropriate amount of context when replying. Not
everyone reads messages in threaded format. Thank you.

Perl Learner wrote:
> i did look at
>
> perldoc -f system
>
> and i didn't understand what they meant by "backticks" (although, it
> now seems fairly obvious from the name itself. i didn't know what they
> meant by that when i first read it and i hence posted the question
> here)


I applaud your having read the documentation, that was an extremely
good thing to do. However, if you do not understand the a piece of the
documentation, the more appropriate path would have been to ask "Can
someone please explain what this piece of documentation means?", rather
than asking the question that was answered (albeit possibly not
clearly) by the docs themselves. That would have much more quickly led
you to a helpful answer.

Out of curiousity, have you read the posting guidelines for this group?
They discuss issues like this (mentioning what docs you've read before
asking your question...).

Paul Lalli

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-23-2005
Perl Learner <(E-Mail Removed)> wrote:

> i did look at
>
> perldoc -f system
>
> and i didn't understand what they meant by "backticks"



Then your post should have been:

What does "backticks" mean?

But that wasn't the question that you asked...


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      06-23-2005
#!/usr/local/bin/perl
#try qx if you don't want to use back ticks in UNIX like environments

$a = qx#which gnuplot#;
print $a ."\n";

 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      06-23-2005
(E-Mail Removed) writes:

> #!/usr/local/bin/perl
> #try qx if you don't want to use back ticks in UNIX like environments
>
> $a = qx#which gnuplot#;
> print $a ."\n";


Gimme, will you *please* quote enough of the message you're replying to, for
your own post to make sense? You've been asked this before - I'm beginning
to get the idea that you're deliberately refusing to do so.

Have a look at this URL:

<http://groups-beta.google.com/support/bin/answer.py?answer=12348&topic=250>

*Especially* the paragraph that begins with "Summarize what you're following
up."

sherm--
 
Reply With Quote
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      06-24-2005
Thanks for the laugh Shrem.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How come I get get my background thread to output anything? grocery_stocker Python 3 04-10-2009 05:21 AM
parse output screen ok but cant get desired output new file! chuck amadi Python 1 06-23-2004 02:16 PM
Is Fuji S3000 3.2m/pixel output, or 6 m/pixel interpolated output? Peter H Digital Photography 43 12-04-2003 02:35 PM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments