How do I get the return value from EXEC ?

Post Reply
sktan
Posts: 2
Joined: Monday 10th June 2019 11:43am

How do I get the return value from EXEC ?

Post by sktan » Monday 10th June 2019 11:55am

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 ?

User avatar
Cedron
Posts: 98
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

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

Post by Cedron » Monday 10th June 2019 2:19pm

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
.... and carry a big stick!

sktan
Posts: 2
Joined: Monday 10th June 2019 11:43am

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

Post by sktan » Monday 10th June 2019 2:46pm

Thanks you! :lol: :lol: :lol: :lol: :lol:
My program can work now!
It annoy me for many days

Post Reply