1

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.

Letal1s
  • 47
  • 2
  • 9
  • Have you inspected `exitCode`, `stdout`, and `stderr` of `testProces` afterward? Were there any error messages? (How did you determine that it didn't run?) You tried using `./test.sh`, but did you try using an absolute path (`/Users/user/testPath/test.sh`)? Are you sure that the current working directory is what you think it is? – jamesdlin May 25 '21 at 20:29
  • I did try an absolute path and had determined it wasn't running as the shell was outputting to a log file that was never created, and the 'say' command in the script wasn't running. I didn't get any output for stdout but I did get a 'command not found' in stderr and an exit code of 127. I did however end up with a solution to the issue with the help of the answer below so I will update the question shortly. – Letal1s May 26 '21 at 17:57

1 Answers1

3

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.

smorgan
  • 20,228
  • 3
  • 47
  • 55
  • Brilliant! I disabled sandboxing before and tested without the "./" before the script name and assumed it didn't work when I got nothing, then went on to use a shell plugin I found. However, now I've gone back and tested this out again with the "./" before my script, the Process.Start() now works! Now I don't need to use a 3rd party plugin :) – Letal1s May 26 '21 at 18:03