import java.io.*;
class PT
{
public static void main(String[] args) throws IOException
{
String filename="out.txt";
if(args.length>0){
filename=args[0];
}
String command="cmd /C dir";
Runtime r=Runtime.getRuntime();
Process p=r.exec(command);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
PrintStream ps=new PrintStream(new FileOutputStream(filename));
String inline;
while(null!=(inline=br.readLine())){
ps.println(inline);
}
System.out.println("a command result has been readed to a file "+filename);
}
}
class PT
{
public static void main(String[] args) throws IOException
{
String filename="out.txt";
if(args.length>0){
filename=args[0];
}
String command="cmd /C dir";
Runtime r=Runtime.getRuntime();
Process p=r.exec(command);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
PrintStream ps=new PrintStream(new FileOutputStream(filename));
String inline;
while(null!=(inline=br.readLine())){
ps.println(inline);
}
System.out.println("a command result has been readed to a file "+filename);
}
}
或是"ps -ef | awk '{ if ($NF ~/'PT'/) print $2}'" 直接找pid
就不行阿,有什么解决办法吗?