如何解决Shell 脚本不会在 MacOS 上使用 Process.Start() 执行 - Flutter
我一直在尝试使用我的 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",workingDirectory: "/Users/user/testPath");
testProcess = await Process.start("bash",["test.sh"],workingDirectory: "/Users/user/testPath");
使用诸如“say”之类的命令可以正常工作,因此似乎只是 shell 脚本无法运行:
testProcess = await Process.start("say",["hello"],workingDirectory: "/Users/user/testPath");
我做错了什么?我知道这可能可以通过 swift 中的自定义插件来完成,但如果可能的话,我宁愿在 dart 中执行此操作。有什么想法吗?
谢谢。
解决方法
macOS Flutter 应用程序是 sandboxed by default,所以除非你为你的应用程序禁用了沙箱(我猜不是这种情况,因为你没有提到它)你的应用程序无法访问路径包含您的 shell 脚本。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。