怎么用exec来执行c:\a.exe? envp - array of strings, each element of which has environment variable settings in format name=value.就是环境变量,比如{"os=winnt", "user=someone"} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果不用设置环境变量呢,好像envp不能为空 exec(String command)就可以了,有适用各种参数的方法嘛 envp 可以为空String[] commands,里是命令和参数 example:import java.io.BufferedInputStream;import java.io.IOException;import java.io.InputStream;public class Command2{ public static void main(String[] args) { String cmd = "ping localhost"; try { Process ps = Runtime.getRuntime().exec(cmd); System.out.print(loadStream(ps.getInputStream())); System.err.print(loadStream(ps.getErrorStream())); } catch(IOException ioe) { ioe.printStackTrace(); } } // read an input-stream into a String private static String loadStream(InputStream is) throws IOException { int ptr = 0; BufferedInputStream bis = new BufferedInputStream(is); StringBuffer buffer = new StringBuffer(); while( (ptr = bis.read()) != -1 ) { buffer.append((char)ptr); } return buffer.toString(); }} 初学JAVA看什么书上手比较快 急求!!!Math类中round(double a)与round(float a)方法的不同 为什么dao要用接口实现 java Date Calendar 疑惑 java中有没有消息机制? 去掉时间后的.0 skip的效率问题??? 一个基础的抽象类的疑问,盼解答..在线! byte/char/short在运算过程中遇到的问题 这是一个按纽程序,帮我注释一下好吗?或帮我改多几个象这样的按纽谢谢 如何在java中访问注册表 Code too large问题
就可以了,有适用各种参数的方法嘛
String[] commands,里是命令和参数
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;public class Command2
{
public static void main(String[] args)
{
String cmd = "ping localhost";
try
{
Process ps = Runtime.getRuntime().exec(cmd);
System.out.print(loadStream(ps.getInputStream()));
System.err.print(loadStream(ps.getErrorStream()));
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
// read an input-stream into a String
private static String loadStream(InputStream is) throws IOException
{
int ptr = 0;
BufferedInputStream bis = new BufferedInputStream(is);
StringBuffer buffer = new StringBuffer();
while( (ptr = bis.read()) != -1 )
{
buffer.append((char)ptr);
}
return buffer.toString();
}
}