Use runtime What is the reason for “the system cannot find the specified file” caused by exec? (Association / ftype)

Who knows why these two statements cause the displayed exception?

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\"");

This is the 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)

Well, I've changed this, but there's still no association, and the same command is executable and works at the CMD command prompt

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\"");

Any additional suggestions? thank you!

Solution

It turns out that Assoc and ftype are built - in shell commands rather than executables The same is true for copying, directories, etc You can start CMD with the / C parameter Exe to pass the command line string, for example, CMD exe / c assoc ….

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>