Discuss Scratch

mobluse
Scratcher
100+ posts

exec, system, or shell_exec from Scratch

In Java, Perl, and PHP you can execute shell commands (e.g. Bash in Linux and Mac OS X, and MS-DOS or PowerShell in Windows) from the language using exec, system, and shell_exec, respectively.

I would like to do the same in Scratch 1.4 and Scratch 2.

The output from the shell-command should be appended to lists e.g. stdout and stderr with one list-item per output line.

I don't know Squeak so its probably impossible for me to solve this for Scratch 1.4. I guess, for Scratch 2 one would have to provide a simple web-server to run the shell commands.

Does anyone know how to do this? I think this would be the simplest way to connect to the physical world, since then you only have to develop command-line utilities that provide measurements etc.

mqtt
New to Scratch
9 posts

exec, system, or shell_exec from Scratch

One approach would be to use Node-Red which makes it simple to exec and collect the resulting stdout, stderr and return code. I blogged on the basics of how to link Scratch 2.0 to Node-Red here: http://davejlocke.wordpress.com/2013/10/14/14/

Powered by DjangoBB