Xojo's "Shell" Command On OSX: A Pain

OK. I open a terminal window manually, and do “bash” and then “wszst”. I get what is expected.

**************-iMac:~ Shane$ bash
bash-3.2$ wszst

		***********************************
		*     _______ _______ _______     *
		*    |  ___  |____   |  ___  |    *
		*    | |   |_|    / /| |   |_|    *
		*    | |_____    / / | |_____     *
		*    |_____  |  / /  |_____  |    *
		*     _    | | / /    _    | |    *
		*    | |___| |/ /____| |___| |    *
		*    |_______|_______|_______|    *
		*                                 *
		*         Wiimms SZS Tools        *
		*       http://szs.wiimm.de/      *
		*                                 *
		***********************************

wszst: Wiimms SZS Tool v1.24a r4703 mac - Dirk Clemens - 2013-10-14
Visit http://szs.wiimm.de/wszst for more info.

-> Type 'wszst -h' or 'wszst help' (pipe it to a pager like 'less') for more help.

However, when executing the same commands (“bash” on Window1’s “Activate” command, and “wszst” on PushButton1’s “Action” command) in a Xojo app, I get the error bash: wszst: command not found. How can the command not be found when I do the exact same thing as I would when manually using the Terminal?

Thanks,
Shane.

The shell environment isn’t the same as the Terminal environment - most likely the path isn’t the same. Provide the full path to the tool and it should work.

Do “which wszst” to figure out the path.

And you cannot ENTER terminal mode in one event and pass commands in another.
For the most part SHELL is EXECUTE and RETURN (with some special exceptions)

But as stated above… each instance of SHELL creates a NEW environment… and needs to be initalized to the proper path etc.

SHELL “BASH”
SHELL “WSZST”

invokes TWO independant OS level environments NOT one where you sent it two commands in sequence

Or, you create a Global level Shell object, open it by executing your favorite shell, and then use WriteLine to the shell to execute commands under that instance of your shell. I use this all the time. Remember, when you’re using the shell, you’re messing around in the Unix realm of OS X. Things are not as straight forward or obvious as you might expect. I recommend the O’Reilly book Learning Unix for OS X. It has a great explanation of what you need to know about the behind the scenes stuff. I’ve been managing Unix systems since 1981 (total BOFH) and I constantly refer to that book and the old world favorite Unix Primer Plus.

Global MyGlobalShell As Shell

In App.Open:

MyGlobalShell.Mode = 2 MyGlobalShell.Execute "/bin/bash" MyGlobalShell.WriteLine "export PATH=... MYVAR=..." // of course, ... should be your required values

Anywhere else in your code:

MyGlobalShell.WriteLine "the command for this situation; echo SHELLDONE" While InStr(MyGlobalShell.Result, "SHELLDONE") = 0 MyGlobalShell.Poll Wend theNeededStr = MyGlobalShell.ReadAll // note: ReadAll clears the buffer for MyGlobalShell while Result does not.

Hope that helps you use the shell more effectively.

[quote=46826:@Tim Jones] MyGlobalShell.Mode = 2
MyGlobalShell.Execute “/bin/bash”
//MyGlobalShell.WriteLine “export PATH=… MYVAR=…”
MyGlobalShell.WriteLine “cd /Users/Mitch/desktop”
// of course, … should be your required values[/quote]

Brilliant.

But it does not work for me. I added a module to my project where I added MyGlobalShell as Shell, but in the Open Event I get an error at run time.

What is the secret ?

TIA

Did you remember to do MyGlobalShell = new Shell before trying to use it?

Kem’s answer is the step I forgot to mention …

In App.Open should be:

MyGlobalShell = New Shell MyGlobalShell.Mode = 2 MyGlobalShell.Execute "/bin/bash" MyGlobalShell.WriteLine "export PATH=... MYVAR=..." // of course, ... should be your required values

Strange thing, when you start with mode 2, it doesnt want to go back in mode 1 (i need mode 1 for a reason)

So i’m Not able to see if my command works with the new export path i gave it…

I’m trying to run ‘convert’ from imagemagick…

Don’t forget…

shell.backend = "/bin/bash"

Here an exemple of my code :

[code]dim str as string = “/usr/local/Cellar/imagemagick/7.0.5-0/bin/convert -density 72 ~/Desktop/test.jpg ~/Desktop/test.jpg”

app.myShell = new xShell // Where xShell is a Shell Class
app.myShell.Mode = 2
App.myShell.Execute “/bin/bash”
App.myShell.WriteLine “export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin”

App.myShell.Mode = 0
App.myShell.Execute(str)[/code]

if i keep Mode 2, the script hang and does nothing (times out)
the problem with Convert, it’s need other programs, and they don’t run with absolute path :-/