Commands inside bash macro do not return output

Hello, I’m want to execute shell script from macro which executes some commands like curl or calling other python scripts. Noticed that bash script runs and even the commands return value inside shell returns true but as in below example the curl output in not generated.

– macro –

Sub execProg() 
    DIM x
     x = Shell(" bash /home/usr1/test_print.sh")
     msgbox(x)
End Sub

---- test_print.sh —

#!/bin/bash
OUT="/home/usr1/test.out"

curl -o test.jpg https://www.keycdn.com/img/example.jpg
if [ $? -eq 0 ]; then
        echo "CURL:$(date)" > $OUT
else
        echo "CURL Failed:$(date)" > $OUT
fi

test.out shows curl succeeded but there is no test.jpg. Any ideas what am i missing here?

The Shell command returns the exit code of the program, not the returned value. You need to store the returned value in a file, then read this file from the macro.

agree, but the real issue is that test.jpg file is not created if run from macro. Though shell script works from bash cmdline. cant find any exaplanation for that.

Append a

printf "%s\n" "$(pwd)" >>$OUT

to your script. Maybe you’re just in an unexpected current working directory…

1 Like

Works for me, (with adjusted path)

#!/bin/bash

curl -o /home/…me…/test.jpg https://www.keycdn.com/img/example.jpg

the msgbox shows just 0 for success

No need for →Basic→shell… you can execute python directly!

1 Like

You didn’t mention your OS and how LibreOffice is installed. If it is part of an container your bash-script may be restricted to the container.

Found that it was an issue with different working directory where it wrote files. Many thanks for the pointer and using python directly from macro. Would be good to explore that.