Shell script won't execute with Process.Start() on MacOS – Flutter

Issue

I’ve been experimenting with using my flutter app to start and stop shell scripts on Windows and MacOS. On Windows I am able to run a batch file using Process.start() and later terminate it successfully, however on Mac my shell script never even seems to start.

My shell script works fine using the terminal (the script is in the directory /Users/user/testPath) using ‘./test.sh’. I have applied ‘chmod +x’ however when using any of these variations I get absolutely nothing running:

testProcess = await Process.start("test.sh", [""], runInShell: true, workingDirectory: "/Users/user/testPath");
testProcess = await Process.start("./test.sh", [""], runInShell: true, workingDirectory: "/Users/user/testPath");
testProcess = await Process.start("bash", ["test.sh"], runInShell: true, workingDirectory: "/Users/user/testPath");

Using commands such as ‘say’ work fine, so it seems like it’s just shell scripts that don’t seem to run:

testProcess = await Process.start("say", ["hello"], runInShell: true, workingDirectory: "/Users/user/testPath");

What am I doing wrong? I know this could likely be done via a custom plugin in swift, but I’d rather do this in dart if possible. Any ideas?

Thanks.

Solution

macOS Flutter applications are sandboxed by default, so unless you have disabled the sandbox for your application (which I’m guessing is not the case since you didn’t mention it) your application does not have access to the path containing your shell script.

Answered By – smorgan

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *