|
From: sfeam <sf...@us...> - 2014-03-02 04:00:19
|
On Sunday, 02 March 2014 01:47:57 AM pl...@pi... wrote:
> Hi,
>
> I'm trying to get a status result back from a system call but am getting
> inconsistent behaviour from the automatic typecasting magic.
>
> bash$ test=OK;echo $test; echo $?
> OK
> 0
>
> gnuplot
> Version 4.7 patchlevel 0 last modified 2012-10-16
> ....
>
> gnuplot> cmd="test=OK;echo $test; echo $?;"
> gnuplot> res=0;print system (cmd);print res
> OK
> 0
> 0
>
> gnuplot> res=0; res= system (cmd);print res
> OK
> 0
>
> gnuplot> res=0; if (res==0) {print "test OK"}
> test OK
>
> gnuplot> res=0; res=res+ system (cmd);print res
> Non-numeric string found where a numeric expression was expected
>
> gnuplot> res=0; res=res || system (cmd);print res
> non-integer passed to boolean operator
>
>
> Now I know automatic typing is _supposed_ to be inconsistent ( it's a
> feature not a bug). but this seems nonsensical.
>
> The first and second invocations are as expected and prints integer zero
> (the status result returned by the shell). So what the heck is it
> complaining about when I try to add integer zero to integer zero?
gnuplot> help system
`system "command"` executes "command" using the standard shell. See `shell`.
If called as a function, `system("command")` returns the resulting character
stream from stdout as a string.
Your printout above shows exactly this.
After setting res = system(...) it is a string
containing "OK\n0"
> How is it that it manages to print the zero result directly but when I
> try to add it , it suddenly becomes a "non numeric" expression? Then a
> "non integer".
It doesn't print 0. It prints "OK\n0"
> Is this really what it's supposed to be doing?
Yes.
Ethan
|