Page 1 of 1

How do I get the return value from EXEC ?

Posted: Monday 10th June 2019 11:55am
by sktan
I've a python program name director.py, I run the python program when my gambas program in running, so that like this
dim sOutPut as string
EXEC ["/home/bakar/director.py 1981 7 30"] TO sOutPut
but fail
gambas said no thus file or directory
why the /home/bakar/director.py exist, but gambas not found it ?

Re: How do I get the return value from EXEC ?

Posted: Monday 10th June 2019 2:19pm
by Cedron
Howdy, and welcome to the forum.

Shorter Answer:

Try:
 EXEC ["python", "/home/bakar/director.py", "1981", "7". "30"] TO sOutPut

Longer Answer:

You probably want to use Shell instead of Exec. They are similar, but different.

http://gambaswiki.org/wiki/lang/exec

http://gambaswiki.org/wiki/lang/shell

In short, Shell is "friendlier". The following code works for me:
        Dim theResult As String

'        Exec ["python", Application.path & "/Hello.py", "3", "4"] To theResult
        
        Shell "python " & Application.path & "/Hello.py 3 4" To theResult
                
        Print "theResult", theResult
Here is Hello.py in my project directory. Note the path is explicitely needed in the shell call.

Code: Select all

import sys

if len( sys.argv ) != 3 :
    print "You must provide two arguments"
    exit

print int( sys.argv[1] ) * int( sys.argv[2] )
And the results I get are: "theResult 12"

If you also want to capture the error output as well as the standard output, that is trickier. See by FFTW RunSh.module for that in the project I attached here:

https://forum.gambas.one/viewtopic.php?f=4&t=689

Hope this helps.

Ced

Re: How do I get the return value from EXEC ?

Posted: Monday 10th June 2019 2:46pm
by sktan
Thanks you! :lol: :lol: :lol: :lol: :lol:
My program can work now!
It annoy me for many days