概述
import java.io.*;
public class Exec {
public static void main(String[] args) throws IOException {
Runtime r = Runtime.getRuntime();
Process p = r.exec("cmd");
PrintWriter writer = new PrintWriter(new OutputStreamWriter(p
.getOutputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(p
.getInputStream()));
writer.println("set path");
writer.println("exit");
writer.flush();
String path = "";
final String prefix = "Path=";
for (String line = null; (line = reader.readLine()) != null;) {
if (line.startsWith("Path=")) {
path = line.substring(prefix.length());
}
}
System.out.println(path);
writer.close();
reader.close();
}
最后
以上就是风中小丸子为你收集整理的获得path变量的全部内容,希望文章能够帮你解决获得path变量所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复