通过JAVA在命令行(如控制台)运行Shell指令
来源:互联网 发布:淘宝网卖家登陆 编辑:程序博客网 时间:2024/06/10 07:09
package com.things.boring.runtime;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class RuntimeTest {
/**
* Run a command in the command line just like the console.
*/
public static void main(String[] args) throws IOException {
Process process = null;
Runtime rt = Runtime.getRuntime();
try {
process = rt.exec("ls -la");
} catch (IOException e) {
e.printStackTrace();
}
try {
process.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream is = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String b;
while((b=br.readLine())!=null){
System.out.println(b);
System.out.println(br.readLine());
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class RuntimeTest {
/**
* Run a command in the command line just like the console.
*/
public static void main(String[] args) throws IOException {
Process process = null;
Runtime rt = Runtime.getRuntime();
try {
process = rt.exec("ls -la");
} catch (IOException e) {
e.printStackTrace();
}
try {
process.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream is = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String b;
while((b=br.readLine())!=null){
System.out.println(b);
System.out.println(br.readLine());
}
}
}
0 0
- 通过JAVA在命令行(如控制台)运行Shell指令
- 通过在uefi shell 命令行启动grub
- 在控制台 通过jdk命令行打开jar文件
- 在命令行运行.java文件
- 在命令行中运行java
- 在 console(控制台)下编译和运行 Java 程序
- 如何用命令行编译、运行第一个java程序(Hello World!)
- 运行控制台命令(java)
- Java通过SSH2协议运行远程shell
- TestNG如何用命令行运行
- TestNG如何用命令行运行
- 【java & c#】通过控制台编译和运行程序//不依赖IDE
- 在命令行通过adb shell am broadcast发送广播
- abd shell命令在windows 命令行下无法运行?
- 在Yarn上运行spark-shell和spark-sql命令行
- 在Yarn上运行spark-shell和spark-sql命令行
- MySql在命令行指令
- 在命令行下运行java工程
- Java中的Enum的使用与分析
- linux下验证码功能不能正常显示
- 2016SDAU编程练习一1003
- Android中FragmentTabHost结合fragment实现选项卡功能
- Android 6.0的权限问题
- 通过JAVA在命令行(如控制台)运行Shell指令
- Ext Grid上双击触发事件
- leetcode89-Gray Code(格雷码)
- 深入理解RunLoop
- [疯狂Java]SQL:DDL语句(定义、修改表结构)
- vc 递归删除非空文件夹
- socket.io简介
- Android TouchEvent事件传递机制
- sqlplus命令的使用大全