实际上,dir, del,copy都是类似ping的一个个小工具,所以它们都是一样的 如果你设了环境变量,就可以直接在下面一句写上 Process process = Runtime.getRuntime().exec ("dir"); Process process = Runtime.getRuntime().exec ("del *.*"); Process process = Runtime.getRuntime().exec ("pine www.163.com");
import java.io.*; class test { public static void main(String []args) { try{ Process process = Runtime.getRuntime().exec("dir"); } catch(IOException e) { System.out.println(e.getMessage()); } }
} 以上代码在我机器上显示: CreateProcess: dir error=2 如果是外部命令就正常,我设置过CLASSPATH 和path
import java.io.*; class test { public static void main(String []args) { try{ Process process = Runtime.getRuntime().exec("dir"); } catch(IOException e) { System.out.println(e.getMessage()); } }} 以上程序在你们的机器上可以调用dir吗?
象 ShellExecute 这个函数我没有试过你可以试一试◎!~?
Process aPro = Runtime.getRuntime().bat("d:\\alpha.bat");它提示BAT不可以
Process p = Runtime.getRuntime().exec(command);
p.waitFor(); %>
你这样试试看!:)我也不知道可不可以! 我只是提参考的:)
import java.io.*;public class javaPing{
public static void main(String[] args){
String pingurl=null;
if(args.length>0) {
pingurl=args[0];
}
else {
pingurl="www.sina.com.cn";
}
pingurl="C:\\WINNT\\system32\\ping.exe "+pingurl;
try
{
Process process = Runtime.getRuntime().exec ("pingurl");
InputStreamReader ir=new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
String line;
while ((line = input.readLine ()) != null)
System.out.println(line);
}
catch (java.io.IOException e){
System.err.println ("IOException " + e.getMessage());
}
}
}
我想要实现的如C里面的system()函数,它内外部命令都可调用,
而我只要调用内部命令。
如果你设了环境变量,就可以直接在下面一句写上
Process process = Runtime.getRuntime().exec ("dir");
Process process = Runtime.getRuntime().exec ("del *.*");
Process process = Runtime.getRuntime().exec ("pine www.163.com");
class test
{
public static void main(String []args)
{
try{
Process process = Runtime.getRuntime().exec("dir");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}
以上代码在我机器上显示:
CreateProcess: dir error=2
如果是外部命令就正常,我设置过CLASSPATH 和path
class test
{
public static void main(String []args)
{
try{
Process process = Runtime.getRuntime().exec("dir");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}}
以上程序在你们的机器上可以调用dir吗?