Get output from system()

P

Perl Learner

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?
 
A

A. Sinan Unur

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
 
T

Tad McClellan

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.
 
J

Jürgen Exner

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
 
P

Perl Learner

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";
 
P

Paul Lalli

Please quote an appropriate amount of context when replying. Not
everyone reads messages in threaded format. Thank you.

Perl said:
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
 
T

Tad McClellan

Perl Learner said:
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...
 
G

gimme_this_gimme_that

#!/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";
 
S

Sherm Pendley

#!/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--
 
P

Perl Learner

Thanks for the replies folks.
Then your post should have been:

What does "backticks" mean?

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

That wasn't the question I asked because when I first
read that word, it sounded so faint that I didn't even think
that the answer would lie in it.

If I knew what it meant at first, I would have found it on the web
myself. I later did exactly that to figure the answer out.

Even if I had asked "what does backticks mean", I wouldn't
be surprised if you'd give another one of those standard replies
with that funny tone.

I am asking questions here because I couldn't find them
online/in the documentation (Sometimes I don't know the
right terms to search for, I can only describe to myself what I want
in plain English, and sometimes these documentation searches/
google searches don't show the right results if you don't have the
right terms to search for). And if I am unable to find what I need,
I come here to post a question.
You need to learn to try searching the standard docs *before*
asking hundreds of people around the world to help you with
your problem.

(apart from what I've said earlier... )
Technically, (most of) everything could be found if you search
hard enough. So basically I can reply to anyone here telling
them to search the documentation and whatnot. But I wouldn't
personally recommend myself using that strategy (or worse,
using that tone)

As for the rest of you guys, I really appreciate all the time and
patience you have shown for my little perl brain so far. All your
comments and suggestions are very valuable to me.
 
T

Tad McClellan

Please provide an attribution when you quote someone.

Thanks for the replies folks.


Even if I had asked "what does backticks mean", I wouldn't
be surprised if you'd give another one of those standard replies
with that funny tone.

Technically, (most of) everything could be found if you search
hard enough. So basically I can reply to anyone here telling
them to search the documentation and whatnot. But I wouldn't
personally recommend myself using that strategy (or worse,
using that tone)


I won't be helping you with an unacceptable tone in the future.
 
A

Arndt Jonasson

Perl Learner said:
Thanks for the replies folks.


That wasn't the question I asked because when I first
read that word, it sounded so faint that I didn't even think
that the answer would lie in it.

I'm curious, what does "faint" mean here? (My native language isn't
English.)
 
T

Tintin

Arndt Jonasson said:
I'm curious, what does "faint" mean here? (My native language isn't
English.)

As an English speaker, it is a very unusual context to use "faint" in. I
think the OP is using it in the sense of "not strong" or possibly "vague".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top