如何执行 Bash 命令并从 Java 收集输出? [英] How do I execute Bash commands and collect the output from Java?

查看:39
本文介绍了如何执行 Bash 命令并从 Java 收集输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何执行 Bash 命令并收集 Java 的输出?

How do I execute Bash commands and collect the output from Java?

大家好,基本上我正在编写一个基本的控制台应用程序,并且希望能够从中运行命令,例如 sudo***、halt、ifconfig 等.

Hi all, basically I am writing a basic console app, and would like to be able to run commands from it, such as sudo***, halt, ifconfig, etc.

有什么见解吗?

推荐答案

可以使用processBuilder API 用于此目的.参见这个例子.

You can use processBuilder API for this purpose. See this example.

这篇关于如何执行 Bash 命令并从 Java 收集输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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