Java调用Linux命令行若干实例
来源:互联网 发布:电脑软件安装 编辑:程序博客网 时间:2024/05/17 06:01
Executing a CommandSee also e90 Reading Output from a Command.
try { // Execute a command without arguments String command = "ls"; Process child = Runtime.getRuntime().exec(command); // Execute a command with an argument command = "ls /tmp"; child = Runtime.getRuntime().exec(command); } catch (IOException e) { }
If an argument contain spaces, it is necessary to use the overload that requires the command and its arguments to be supplied in an array:
try { // Execute a command with an argument that contains a space String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"}; commands = new String[]{"grep", "hello world", "c://Documents and Settings//f.txt"}; Process child = Runtime.getRuntime().exec(commands); } catch (IOException e) { }
e90. Reading Output from a Command
try { // Execute command String command = "ls"; Process child = Runtime.getRuntime().exec(command); // Get the input stream and read from it InputStream in = child.getInputStream(); int c; while ((c = in.read()) != -1) { process((char)c); } in.close(); } catch (IOException e) { }e91. Sending Input to a Command
try { // Execute command String command = "cat"; Process child = Runtime.getRuntime().exec(command); // Get output stream to write from it OutputStream out = child.getOutputStream(); out.write("some text".getBytes()); out.close(); } catch (IOException e) { }
- Java调用Linux命令行若干实例
- Java 调用CMD 命令行 经典实例
- WINDOWS/LINUX下JAVA命令行调用FFMPEG
- java 调用linux实例代码
- java 中this调用静态变量及实例变量的若干错误
- Java的时间操作玩法实例若干
- java调用windows命令行
- Java调用dos命令行
- Java调用命令行
- java调用命令行
- JAVA调用命令行
- Java调用命令行
- Java 调用命令行
- 如何用java调用linux操作系统下的命令行
- JAVA调用linux中的shell命令行的工具类
- centos7 若干命令行笔记
- 实例解说Linux命令行uniq
- 实例解说Linux命令行uniq
- Experience in creating an Axtivex
- 那时的我们
- 集合类
- SiteMesh学习入门
- 迷茫
- Java调用Linux命令行若干实例
- [C++学习笔记]寻找地址
- 大型ORACLE数据库优化设计方案
- java.lang.string
- 数据库三级模式
- Oracle 树型结构查询
- 网络缓存大小引发的问题
- spring连结数据库(jdbc , hibernate)
- pku1485 Fast Food