问题描述
public class dddd {/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {// TODO Auto-generated method stubRuntime run = Runtime.getRuntime(); Process pro = run.exec("cmd /c start tclsh85 e:dddd.tcl"); //Process pro = run.exec("cmd /c start dir"); //Process pro = run.exec("cmd /c "); BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream())); String str = ""; br.readLine(); while((str = br.readLine()) != null) { System.out.println("str="+str); } br.close(); pro.destroy(); }}运行这段代码怎么没输出,没有报异常,但在dos下有输出 问题补充:nju_abc 写道
解决方案
ProcessBuilder builder = new ProcessBuilder("java","-cp","e:/","dddd");
解决方案二:
引用还是不知道怎么实现,请您告诉我如果要编译e盘dddd.java文件应该怎么写?谢啦 ProcessBuilder builder = new ProcessBuilder("javac","-verbose","e:/dddd.java");
解决方案三:
引用ProcessBuilder builder = new ProcessBuilder("javac","/c","e:dddd.java"); e:dddd.java少了盘符你是不是要生成所有编译信息?如果是的话代码是下面这个样子ProcessBuilder builder = new ProcessBuilder("javac","-verbose","e:/dddd.java");
解决方案四:
引用str=-help 用于列出可能的选项 请问/c这个参数应该怎么填 javac 没有/c这个参数,如果要制定classpath,输入-classpath
解决方案五:
你又发了一次。。。引用Process pro = run.exec("cmd /c start tclsh85 e:dddd.tcl"); 首先会将传进来的String按分隔符分解成数组,数组的第一个元素为要执行的命令,其余的作为参数。执行结果可能输出到stdin或stderr中。对应获取的输入流分别为pro.getInputStream()或pro.getErrorStream()。所以最好的方式是用ProcessBuilder将错误输出流和标准输出流合并,如: ProcessBuilder builder = new ProcessBuilder("cmd","/c","dir"); builder.redirectErrorStream(true); Process pro = builder.start(); BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream())); String str = ""; while ((str = br.readLine()) != null) { System.out.println("str=" + str); } br.close(); pro.destroy();