首页新闻找找看学习计划

唉…… Java Runtime.exec() 貌似真的执行不了curl命令哎

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-09-24 08:55

如题:

import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class ExecLinuxCMD {

    public static Object exec(String cmd) {
        try {
            String[] cmdA = { "/bin/sh", "-c", cmd };
            Process process = Runtime.getRuntime().exec(cmdA);
            LineNumberReader br = new LineNumberReader(new InputStreamReader(
                    process.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                sb.append(line).append("\n");
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        String str = exec("/usr/bin/curl").toString();
        System.out.println(str);
    }

}
duanguyuan的主页 duanguyuan | 初学一级 | 园豆:136
提问于:2014-04-04 17:34
< >
分享
所有回答(1)
0

???????????

达兔哥 | 园豆:194 (初学一级) | 2016-10-13 11:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册