我一直在尝试使用我的flutter应用程序在Windows和MacOS上启动和停止shell脚本。在Windows上,我可以使用Process.start((运行批处理文件,然后成功终止它,但在Mac上,我的shell脚本似乎从未启动过。
我的shell脚本使用终端运行良好(脚本位于/Users/user/testPath目录中(/test.sh。我已经应用了chmod+x,但是当使用这些变体时,我完全没有运行任何东西:
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");
使用诸如"say"之类的命令可以很好地工作,所以它似乎只是没有运行的shell脚本:
testProcess = await Process.start("say", ["hello"], runInShell: true, workingDirectory: "/Users/user/testPath");
我做错了什么?我知道这可能通过swift中的自定义插件来实现,但如果可能的话,我宁愿在dart中实现。有什么想法吗?
谢谢。
macOS Flutter应用程序默认情况下是沙盒的,所以除非您为应用程序禁用了沙盒(我猜不是这样,因为您没有提到它(,否则您的应用程序无法访问包含shell脚本的路径。