简体   繁体   English

调用Runtime.getRuntime()EXEC(命令)。 与虚拟硬盘驱动器不起作用?

[英]Runtime.getRuntime().exec(command); With virtual hard drive not working?

I did below: 我在下面做了:

subst A: "C\Desktop"

Now from java code: 现在从Java代码开始:

String command= "java -jar A:\test.jar"
Process process = Runtime.getRuntime().exec(command);

The JVM seems to be hanged here and never executing this line. JVM似乎挂在这里,从不执行此行。 When i run through "java -jar C:\\Desktop\\test.jar". 当我通过"java -jar C:\\Desktop\\test.jar". It executes succefully. 它成功执行。

Does Runtime.getRuntime doesn't resolve virtual hardrive? Runtime.getRuntime是否不能解析虚拟hardrive? Thanks 谢谢

I assume you have \\\\t and not \\t and you are reading from the error stream so you can see any errors. 我假设您有\\\\t而不是\\t并且您正在从错误流中进行读取,因此可以看到任何错误。 \\t is the tab character. \\t是制表符。

(The joys of MS-DOS using \\ as a path separator ;) (使用\\作为路径分隔符的MS-DOS的乐趣;)

Dump out the error you are getting and you should see the problem. 转储您遇到的错误,您应该会看到问题。

Javadoc of java.lang.Process says java.lang.Process的Javadoc说

The parent process uses these streams to feed input to and get output from the subprocess. 父流程使用这些流将输入馈入子流程并从子流程获取输出。 Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock. 由于某些本机平台仅为标准输入和输出流提供了有限的缓冲区大小,因此无法及时写入子流程的输入流或读取子流程的输出流可能导致子流程阻塞,甚至死锁。

meaning you are not either reading or writing the data promptly that causes buffer overflow in the associated process. 这意味着您不会立即读取或写入数据,从而导致关联进程中的缓冲区溢出。 This could be a possible problem. 这可能是一个问题。 Please read the article on javaworld and consider implementing the reads and writes in separate threads promptly. 请阅读有关javaworld的文章 ,并考虑迅速在单独的线程中实现读写操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM