gpt4 book ai didi

java - 是什么导致 Runtime.exec 出现 "system cannot find the file specified"? (关联/ftype)

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:15:21 26 4
gpt4 key购买 nike

有谁知道为什么这两个语句会导致显示的异常?

Runtime.getRuntime().exec("assoc .vlan=\"file type description\"");
Runtime.getRuntime().exec("ftype \"file type description\"=" + System.getProperty("user.home")+ "\\folder 1\\folder 2\\my executable.exe\" /inject \"%1\"");

这是异常(exception)。

java.io.IOException: Cannot run program "assoc": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)

好吧,我已经改变了这个,但仍然没有建立关联,而完全相同的命令是可执行的,并且在 cmd 命令提示符下工作。

Runtime.getRuntime().exec("cmd.exe /c assoc .vlan=\"file type description\"");
Runtime.getRuntime().exec("cmd.exe /c ftype \"file type description\"=\"" + System.getProperty("user.home") + "\\folder 1\\folder 2\\my executable.exe\" /inject \"%1\"");

有什么补充建议吗?谢谢!

最佳答案

事实证明,assocftype是内置的 shell 命令而不是可执行文件。 copy也是如此, dir等。您可以做的是启动 cmd.exe使用 /c传递命令行字符串的参数,例如cmd.exe /c assoc ... .

关于java - 是什么导致 Runtime.exec 出现 "system cannot find the file specified"? (关联/ftype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com