java调用shell命令的两种方法
2014-03-27 20:14
609 查看
运行环境: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
可以借鉴转码译文分析
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
相关文章推荐
- java本地调用cmd,shell命令,远程调用Linux执行命令方法总结
- awk调用shell命令的两种方法:system与print
- java本地调用cmd,shell命令,远程调用Linux执行命令方法总结
- java 执行命令、调用bat文件、调用外部程序的两种方法
- awk调用shell命令的两种方法:system与print
- Java调用Shell命令的方法
- windows到linux下面文本从ansi转utf-8(java调用shell命令,java文件复制)
- java调用shell命令并获取执行结果
- java调用Linux 命令、Shell脚本
- Redis(Windows安装方法与Java调用实例 & 配置文件参数说明 & Java使用Redis所用Jar包 & Redis与Memcached区别 & redis-cli.exe命令及示例)
- C语言调用shell命令方法
- Java调用Windows控制台命令方法介绍
- Shell脚本中调用、引用、包含另外一个脚本文件的两种方法
- 六种调用shell命令的方法
- Java 调用 Shell 命令
- Java调用WebService(axis2)两种方法
- Windows系统中Java调用cmd命令及执行exe程序的方法
- PHP中调用Java类的两种方法
- 重复调用ab命令的shell代码和整理ab结果的java代码
- 如何在java程序中调用linux命令或者shell脚本