运行DOS应用程序

playgb 2003-01-25 11:33:28
import java.io.*;
import java.util.*;
/**
*
* @author zhuang
* @version
*/
public class dosexec
{
public static String[] runCommand(String[] cmd)
throws IOException
{
ArrayList list = new ArrayList();
Process proc = Runtime.getRuntime().exec(cmd);
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
String str;
while ((str = br.readLine()) != null)
list.add(str);
try
{
proc.waitFor();
}
catch (InterruptedException e)
{
System.err.println("process was interrupted");
}
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
br.close();
return (String[])list.toArray(new String[0]);
}
public static void main(String args[])
{
try
{
String[] comm = {"dir", "*.*"};
String outlist[] = runCommand(comm);
for (int i = 0; i < outlist.length; i++)
System.out.println(outlist[i]);
}
catch (IOException e)
{
System.out.println(e);
}
}
}

java.io.IOException: CreateProcess: dir *.* error=2
我的操作系统是window2000
有没有其它方法。
...全文
69 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovexigua512013 2003-09-14
  • 打赏
  • 举报
回复
好~·~
chaojinn 2003-02-22
  • 打赏
  • 举报
回复
import java.io.*;

class exectest
{
public static void main(String[] args)
{
try {
String cmd = "cmd /c dir f:";
Process child = Runtime.getRuntime().exec(cmd);
InputStream child_in = child.getInputStream() ;
BufferedReader inbr=new BufferedReader(new InputStreamReader(child_in));

String line;
line=inbr.readLine();
while (line!=null)
{
System.out.println(line);
line=inbr.readLine();
}
child_in.close();
child.destroy() ;
} catch (IOException e) {
System.err.println(e);
}
}

}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧