从 Java 调用 Unix 命令
如何通过从 Java 程序内部调用该命令来执行 Unix grep
程序以搜索一组文件中的模式?
How do I execute the Unix grep
program to search for patterns in a set of files by calling that command from inside a Java program?
如何通过从 Java 程序内部调用该命令来执行 Unix grep
程序以搜索一组文件中的模式?
How do I execute the Unix grep
program to search for patterns in a set of files by calling that command from inside a Java program?
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
您可以使用
Runtime.exec< /代码>
编辑:正如 Joachim 和 andypandy 指出的那样,
ProcessBuilder
具有更灵活的界面,如果您在 JDK7 或更高版本上运行,则提供对设置子进程文件描述符的支持。You can use
Runtime.exec
EDIT: As Joachim and andypandy point out,
ProcessBuilder
has a more flexible interface, and if you're running on JDK7 or later provides support for setting up sub-process file descriptors.