Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在授予Java中macOS的权限后运行.command文件_Java_Macos_Terminal_Runtime_Desktop - Fatal编程技术网

在授予Java中macOS的权限后运行.command文件

在授予Java中macOS的权限后运行.command文件,java,macos,terminal,runtime,desktop,Java,Macos,Terminal,Runtime,Desktop,我试图在macOS的Java程序中生成并执行一个.command文件 程序成功地生成了文件,但问题出在执行上 Runtime.getRuntime().exec("chmod a+x \"" + U.base + File.separator + "/Game/run.command\""); Desktop.getDesktop().open(new File(U.base, "Game/run.command")); 运行此命令时,仍会显示弹出对话框: 无法执行文件“run.command

我试图在macOS的Java程序中生成并执行一个.command文件

程序成功地生成了文件,但问题出在执行上

Runtime.getRuntime().exec("chmod a+x \"" + U.base + File.separator + "/Game/run.command\"");
Desktop.getDesktop().open(new File(U.base, "Game/run.command"));
运行此命令时,仍会显示弹出对话框:

无法执行文件“run.command”,因为您没有适当的访问权限

但是,当我在终端中单独手动运行命令“chmoda+xfilepath”时,程序能够执行该文件。我假设这是我使用“Runtime.getRuntime().exec()”的问题


有没有办法解决这个问题?

您可能还需要设置
chmod 755

chmod a+x
会将exec位添加到文件中,但不会接触其他位。例如,
其他人
可能仍然无法读取文件

chmod 755
将始终使用perms 755创建文件,无论初始权限是什么


如果它仍然不起作用,最好有一个异常进行分析。

在运行时运行
chmod
命令时,它显然会使用引号(\”)作为路径的一部分。当我从末尾删除引号时,它起作用了。

好的,所以我输出了运行时进程的结果,它说没有这样的文件或目录。当我从末尾删除引号(\”)时,它起作用了!但是,现在我删除了引号,如何允许文件夹中可能有空格?例如,当路径为:
/Users/dilan/Documents/dmsudater/DMS_V-B/Game/test boi/runMC.command
时,它表示:
chmod:/Users/dilan/Documents/dmsudater/DMS_V-B/Game/test:没有这样的文件或目录chmod:boi/runMC.command:没有这样的文件或目录
如果您有一个带有空格的文件夹或文件,你需要在空格前面加上一个反斜线“\”。例如“/Users/dilan/Documents/DMSUpdater/DMS_V-B/Game/test\\boi/runMC.command”。请接受前面的答案,谢谢。