For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2007 > system()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author system()
Doroshok Stanislav

2007-02-16, 6:59 pm

hi all

I need output from system():

@rrd = ("/usr/bin/rrdtool","graph","-","--title","hypergraph",........);
$rezult = system(@rrd);

how can i get output?
p.s. i don't wont use `` and run shell;
thanks



Jeff Pang

2007-02-16, 6:59 pm


>p.s. i don't wont use `` and run shell;


Why don't ue ``? system() call would also fork a child process to do the things,as `` do.

--
Jeff Pang
EMAIL: pangj@earthlink.net AIM: jeffpang
Paul Lalli

2007-02-16, 6:59 pm

On Feb 16, 8:58 am, save...@volia.net (Doroshok Stanislav) wrote:
> I need output from system():


You may as well have just said "I need pop() to add an element to a
list." That's not what system() does. No way around that.

> @rrd = ("/usr/bin/rrdtool","graph","-","--title","hypergraph",........);
> $rezult = system(@rrd);
>
> how can i get output?


Well, the normal answer is to point you at `perldoc -q system` and
tell you to use backticks, but...

> p.s. i don't wont use `` and run shell;


Out of curiousity, why?

In any case, open a pipe to the process instead.

open my $ph, '-|', @rrd or
die "Cannot start program $rrd[0] with args @rrd[1..$#rrd]: $!\n";
my $rezult;
while (my $line = <$ph> ) {
$rezult .= $line;
}

perldoc -f open
perldoc perlopentut

Paul Lalli

Mumia W.

2007-02-16, 6:59 pm

On 02/16/2007 07:58 AM, Doroshok Stanislav wrote:
> hi all
>
> I need output from system():
>
> @rrd = ("/usr/bin/rrdtool","graph","-","--title","hypergraph",........);
> $rezult = system(@rrd);
>
> how can i get output?
> p.s. i don't wont use `` and run shell;
> thanks
>
>
>
>


The command "perldoc -f open" shows you how to do get the output from a
command without starting a shell.


Jeff Pang

2007-02-16, 9:59 pm


>The command "perldoc -f open" shows you how to do get the output from a=20
>command without starting a shell.
>


Do you mean open a pipe? It still need to fork a child process for running =
the external commands.

--
=E7=A5=9D=E6=89=80=E6=9C=89=E4=B8=AD=E5=
8D=8EPerl=E7=94=A8=E6=88=B7=E6=96=
=B0=E6=98=A5=E5=BF=AB=E4=B9=90!
Happy New Year for all Chinese Perl guys!
Mumia W.

2007-02-16, 9:59 pm

On 02/16/2007 07:25 PM, Jeff Pang wrote:
>
> Do you mean open a pipe? It still need to fork a child process for running the external commands.
>


Read the "safe pipe opens" section of "perldoc perlipc"; IOW, use the
"list" form of the open command.


Paul Lalli

2007-02-17, 6:58 pm

On Feb 16, 8:25 pm, p...@earthlink.net (Jeff Pang) wrote:
>
> Do you mean open a pipe? It still need to fork a child process for running the external commands.


Yes, and? The OP just said he doesn't want to invoke a shell, not
that he doesn't want to fork a process.

Paul Lalli

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com