使用管道获取运行时? [英] getRuntime with pipe?

查看:67
本文介绍了使用管道获取运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在java程序中执行以下命令.但它只执行第一部分.之后的部分 |未执行

I want to execute the following command in a java program. But it execute only the first part. the part after | is not executed

Process process = Runtime.getRuntime().exec(" adb devices | tail -n +2 | cut -sf 1");

        process.waitFor();

推荐答案

你需要在 shell 中运行它.试试这个:

You need to run that in a shell. Try this:

Process process = Runtime.getRuntime().exec(new String[] {
        "/bin/sh",
        "-c",
        "adb devices | tail -n +2 | cut -sf 1"
});
process.waitFor();

这篇关于使用管道获取运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆