java调用shell命令的两种方法
来源:互联网 发布:帝国cms灵动标签大全 编辑:程序博客网 时间:2024/05/01 14:33
运行环境:centos6.5 eclipse
可以借鉴转码译文分析
public static void insert(){
String pathshell="/home/wjx/spider/baidu/java.sh";//String cmd="sort /home/wjx/spider/baidu/SearchUrl_CSDN.txt | uniq >/home/wjx/spider/baidu/SearchUrl_CSDN_b.txt;sort /home/wjx/spider/baidu/SearchUrl_OSchina.txt | uniq >/home/wjx/spider/baidu/SearchUrl_OSchina_b.txt";
Process ps;
try {
//ps = Runtime.getRuntime().exec(new String[]{"sh","-c",cmd});
ps = Runtime.getRuntime().exec(pathshell);
ps.waitFor();
String path = "/home/wjx/spider/baidu/";
File f = new File(path);
String[] names = f.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.indexOf(".txt") != -1;// 等于-1,表示不存在
}
});
for (String str : names) {
if (str.endsWith("_b.txt"))
//insert_b(path + str);
if (str.endsWith("_v.txt"))
;
}} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
"/home/wjx/spider/baidu/java.sh" 中的shell脚本:
sort /home/wjx/spider/baidu/SearchUrl_CSDN.txt | uniq >/home/wjx/spider/baidu/SearchUrl_CSDN_b.txt
sort /home/wjx/spider/baidu/SearchUrl_OSchina.txt | uniq >/home/wjx/spider/baidu/SearchUrl_OSchina_b.txt
0 0
- java调用shell命令的两种方法
- 六种调用shell命令的方法
- java 执行命令、调用bat文件、调用外部程序的两种方法
- 简单的调用shell命令的方法。
- python调用shell命令的方法
- ruby调用执行shell命令的方法
- python 调用shell命令的方法
- python 调用shell命令的方法
- python 调用shell命令的方法
- Python调用shell命令的几种方法(在新进程中执行shell命令)
- Java调用Linux命令两种方式的例子
- Java中调用windows cmd命令的两种方式
- Java调用Linux命令两种方式的例子
- Java 调用 Shell 命令
- Java 调用 Shell 命令
- java调用shell命令
- Java 调用 Shell 命令
- java 调用shell命令
- [XCode]XCode 3.2 常用快捷键
- 快速排序
- linux shell读书笔记---find
- 第五周 矩形类
- 雨落江满泛涟漪 尘拂心海滤情音 相思入云寄清风
- java调用shell命令的两种方法
- ARM Architecture C 语言寻址解析—— 从U-Boot relocation所展开的探索(三)
- LeetCode:Populating Next Right Pointers in Each Node I & II
- mac下配置svn服务器
- Nyoj 456
- Lua自定义方式加载模块
- GIT总结
- [Cocoa]深入浅出 Cocoa 之消息
- 如何学习vc+(vc的用处)