[Gambas-user] Reply: No EXEC Output but Works in Terminal

Doriano Blengino doriano.blengino at ...1909...
Wed Mar 4 19:54:23 CET 2009


Jussi Lahtinen ha scritto:
...

Well, I have to be more precise. Sorry mr. Person to have been too 
concise. I understand that docs are not the best, but I did understand 
them with just a little effort, thanks to other knowledges you perhaps miss.
And I made a mistake when speaking of WAIT in combination of "TO xxx". 
But in the docs this is explained.

EXEC takes a number of parameters from 1 to "n". The first is the 
executable to launch, and it must be a true executable. As "test.sh" is 
not a true executable, but a shell script, the "sh" has to be used. 
Normally, sh is used with parameter "-c" to execute a command. So I 
would use:

    EXEC ["/bin/sh", "-c", Application.path &/ "test.sh"] TO sOutPut

Pay attention to where test.sh is, and files needed by it.

> I tried your code... (first I did move test.sh to execution folder).
> With me, this;
> EXEC ["sh", Application.Path &/ "test.sh"] TO sOutPut
> works well.
>   
This seems to work also, ok...

> But this;
> EXEC ["sh " & Application.Path &/ "test.sh"] TO sOutPut
> does NOT work (no output).
> So EXEC command is pretty picky. Benoit, comments?
>   
This is erroneous, because the first parameter has to be an executable. 
The above statement tries to launch a file named "sh /home/test/test.sh" 
or something like that. That's why it does not work. I would be a little 
surprise to see a file with slash characters in its name... (if someone 
wonders, well, it is possible even if is almost never used).

As it happens, the "sh -c" is so useful that gambas has a shorter way to 
call it: SHELL. "SHELL sCommand" is nothing else than "EXEC ["/bin/sh", 
"-c", sCommand]".

>> I tried EXEC ["full path/test.sh"] WAIT to sOutPut but it died. top
>> showed nothing running.
>>
>> Can you show me an example of EXEC . . . WAIT with a variable returned?
>>     
There are examples in the documentation, anyway my file manager removes 
files using:

      SHELL "rm -r \"" & fname & "\" 2>&1" TO name
      IF name <> "" THEN
        Message.Info(name)
        ........


This example works. Notice that the notation 2>&1 works only for SHELL 
(or for sh -c), because is /bin/sh syntax. It works like this: file 
manager simply pass the dirty work to the shell. The shell executes "rm 
-r", and catches both normal output and standard error in one single 
channel, which gambas read and stores in variable "name". If this 
variable is not empty, then something went wrong, and the message is 
showed to the user. If no errors happen, "name" is empty and the 
deletion went well.


Regards,
Doriano







More information about the User mailing list