D:\>a.exe inputfiel -p outputfile
inputfile表示输入的文件,-p是一个属性,outputfile表示输出的文件,我想在java中如何执行,知道用RunTime.exec(cmd);,但是这个cmd怎么写?
9 个解决方案
#1
Runtime.exec("d:/a.exe inputfiel -p outputfile");
就这么写就可以
#3
学习了,thanks
#4
我用getErrorStream得到的是 Couldn't open file 'inputfile'
#5
那个inputfile和outputfile是你的文件路径 是参数。。。
#6
是的,比如inputfile = "D:\\data\\a.doc",outputfile = "D:\\data\\b.doc"
Runtime.exec("d:/a.exe " + inputfiel + " -p " + outputfile);
getErrorStream得到的是 Couldn't open file 'D:\\data\\a.doc'
Runtime.exec("d:/a.exe " + inputfiel + " -p " + outputfile);
getErrorStream得到的是 Couldn't open file 'D:\\data\\a.doc'
#7
你这个a.exe具体什么功能?
#8
搞定了,使用老紫竹提供的第二种方法,参数之间有空格使用数组
try {
String commons[] = {"D:\\a.exe" ,"D:\\data\\aa.doc","-p","D:\\data\\bb.doc"};
Process child = Runtime.getRuntime().exec(commons);
BufferedReader buf = new BufferedReader(new InputStreamReader(child.getErrorStream()));
String str = "";
while((str = buf.readLine())!= null)
{
System.out.println(str);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
#1
Runtime.exec("d:/a.exe inputfiel -p outputfile");
就这么写就可以
#2
#3
学习了,thanks
#4
我用getErrorStream得到的是 Couldn't open file 'inputfile'
#5
那个inputfile和outputfile是你的文件路径 是参数。。。
#6
是的,比如inputfile = "D:\\data\\a.doc",outputfile = "D:\\data\\b.doc"
Runtime.exec("d:/a.exe " + inputfiel + " -p " + outputfile);
getErrorStream得到的是 Couldn't open file 'D:\\data\\a.doc'
Runtime.exec("d:/a.exe " + inputfiel + " -p " + outputfile);
getErrorStream得到的是 Couldn't open file 'D:\\data\\a.doc'
#7
你这个a.exe具体什么功能?
#8
搞定了,使用老紫竹提供的第二种方法,参数之间有空格使用数组
try {
String commons[] = {"D:\\a.exe" ,"D:\\data\\aa.doc","-p","D:\\data\\bb.doc"};
Process child = Runtime.getRuntime().exec(commons);
BufferedReader buf = new BufferedReader(new InputStreamReader(child.getErrorStream()));
String str = "";
while((str = buf.readLine())!= null)
{
System.out.println(str);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}