Unix Shell - Catch the outputs of an external commands

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > Catch the outputs of an external commands





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 Catch the outputs of an external commands
di0rz`

2007-02-25, 1:25 am

Hi, i am lookin for some help with bash.
I try to catch the result of an external command in a variable with
that:
VAR=$(./mysoftware)
but it only takes one of the 3 numbers of the output (the lastone)
how can i grab the 3 results in 3 diferents var ?

(the software send that:
printf("%d, %d, %d\n", result[0], result[1], result[2]);

)

thx

Bo Yang

2007-02-25, 7:20 am

di0rz` :
> Hi, i am lookin for some help with bash.
> I try to catch the result of an external command in a variable with
> that:
> VAR=$(./mysoftware)


The above command will assign what the mysoftware output to VAR.

> but it only takes one of the 3 numbers of the output (the lastone)
> how can i grab the 3 results in 3 diferents var ?
>
> (the software send that:
> printf("%d, %d, %d\n", result[0], result[1], result[2]);
>
> )
>


I think there must be some wrong in your software, there is no error in
the shell command here. If the software send three numbers as you write,
the VAR will be assigned all of them.

Phil Jackson

2007-02-25, 1:17 pm

Bo Yang <struggle@mail.nankai.edu.cn> writes:

> di0rz` :
>
> The above command will assign what the mysoftware output to VAR.


Might be worth mentioning that it will only capture stdout.

Cheers,
Phil Jackson
--
Doughnuts. Is there anything they can't do?
Barry Margolin

2007-02-26, 1:21 am

In article <1172385772.215318.38260@m58g2000cwm.googlegroups.com>,
"di0rz`" <rdelsalle@gmail.com> wrote:

> Hi, i am lookin for some help with bash.
> I try to catch the result of an external command in a variable with
> that:
> VAR=$(./mysoftware)
> but it only takes one of the 3 numbers of the output (the lastone)
> how can i grab the 3 results in 3 diferents var ?
>
> (the software send that:
> printf("%d, %d, %d\n", result[0], result[1], result[2]);
>
> )


If you want to get them into three different variables, use:

set -- $(./mysoftware)
VAR1=$1
VAR2=$2
VAR3=$3

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
jambesh@gmail.com

2007-02-27, 7:21 am

You can also use an array like

set -A myvar $(./mysoftware)
then use the three variable as myvar[0],myvar[1],myvar[2]

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com