【发布时间】:2015-10-08 10:47:37
【问题描述】:
我想通过eclipse java运行其他系统中的bat文件。下面是bat文件在我们系统中运行的代码。
import java.io.IOException;
import java.io.InputStream;
public class batchFile_execution_throught_java {
public static void main(String[] args) {
Runtime runtime = Runtime.getRuntime();
try
{
Process p1 = runtime.exec("cmd /c C:\\Users\\root\\Desktop\\sample.bat");
InputStream is = p1.getInputStream();
int i = 0;
while( (i = is.read() ) != -1)
{
System.out.print((char)i);
}
}
catch(IOException ioException)
{
System.out.println(ioException.getMessage() );
}
}
}
【问题讨论】:
-
你不能在windows配置中创建一个共享文件夹来指向远程计算机吗?
-
我需要在其他系统中运行 bat 文件并在我的 eclipse 控制台中输出
-
那没有回答我的问题... :) 请检查我的答案以获得进一步的解释
-
另请注意,您处理 exec() 调用及其流的实现可能会无限期挂起 - 请参阅 javaworld.com/article/2071275/core-java/…
标签: java eclipse batch-file