- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
有谁知道为什么这两个语句会导致显示的异常?
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\"");
有什么补充建议吗?谢谢!
最佳答案
事实证明,assoc
和 ftype
是内置的 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/
(不确定这是否属于 super 用户,但这里似乎有一个 cmd.exe 标签,所以这里...) 作为背景,我正在研究一个 Firefox 附加组件(这个问题不需要 Firefox 的知识,顺便说一句,
我正在编写一个派生自 ExtJS 网格的通用类,我必须检查工具栏实例化期间是否使用了 grouping 功能(如果启用了 grouping,我想自动添加两个按钮来折叠/展开所有组)。 var grou
我一直在使用 winapi 一点点,制作一个所有者在菜单上绘制的项目。当我调用 GetMenuItemInfo 时,它会设置菜单项的文本,但不会设置 fType UINT 变量标志。 目前我已经声明:
我认为所有 cmd 命令在 Powershell 下的工作方式都是相同的。例如 assoc 和 ftype 不起作用。有没有办法让它们工作而不是再次切换到 cmd? 最佳答案 哦,它们可以工作,但您必
Linux 中是否有 ASSOC 和 FTYPE 的等价物? 在 Windows 上,我可以使用 ftype 定义文件类型。例如: assoc .pl=PerlScript ftype PerlScr
我在 WindowsXP 上。这似乎会影响任何进程,但我将使用 Python3.2 来演示它。一个脚本,'filter.py': import sys for line in sys.stdin:
有谁知道为什么这两个语句会导致显示的异常? Runtime.getRuntime().exec("assoc .vlan=\"file type description\""); Runtime.ge
我是一名优秀的程序员,十分优秀!