package cn.shell;
import java.io.IOException;
import org.apache.hadoop.util.Shell; public class ShellDemo { public static void main(String[] args) throws IOException {
String pars="ipconfig";
String out=Shell.ShellCommandExecutor.execCommand(pars);
System.out.println(out);
}
}

上面是很简单的一个例子,注意Shell.ShellCommandExecutor.execCommand内的参数:

  

demo2:判断yarn 的队列中是否有任务提交,队列可以指定。

    public static boolean hasAppBeSubmited(String queueName){
boolean tag=false;
try {
String out=Shell.ShellCommandExecutor.execCommand("yarn", "application", "-list");
String[] apps =out.split("Tracking-URL");
if(apps.length ==2) {
tag = apps[1].contains(queueName);
}
} catch (IOException e) {
e.printStackTrace();
}
return tag;
}

demo3:shell对管道符号'|' 和重定向符号‘>’ 的支持,需要用sh -c 后边拼接命令

Shell.ShellCommandExecutor.execCommand("sh", "-c","hadoop fs -text hdfs文件  >  本地文件");

注意如果直接执行命令
Shell.ShellCommandExecutor.execCommand("hadoop", "fs", "-text","hdfs文件路径",">" "本地文件");
会报错,会把">"符号当作文件路径处理。所以需要sh -c "命令参数" 讲命令行当作整体传入

demo4:直接用Shell切分文件

Shell.ShellCommandExecutor.execCommand("split","-l", "10000", "--numeric-suffixes=1","--suffix-length=3", "--additional-suffix=.txt",srcFile,newFile);  

demo5:执行shell或者python脚本

Shell.ShellCommandExecutor.execCommand("./ftp.sh",ftpHost,ftpPort,user,password,putPath+File.separator+date,fileDir);

最新文章

  1. Gradle 使用本地的Jar包(gradle oracle ojdbc14 )
  2. Elasticsearch——多索引的使用
  3. sublimetext
  4. DHU-1241 Oil Deposits
  5. python getpass模块:隐藏不显示输入的密码
  6. iOS 在下面 AOP 程序
  7. 禁止使用test类的就是禁止使用本来的$this对象.可以调用父类的对象
  8. 【转】CentOS 6.3(x86_64)下安装Oracle 10g R2
  9. HTML5详解(一)
  10. Codeforces Round #467 (div.2)
  11. 利用js实现 禁用浏览器后退
  12. CentOS 7 配置DHCP中继代理服务
  13. js获取当前页面的url网址信息小汇总
  14. IDEA安装Lombok插件失败的解决方案
  15. Native/Webview bridge for Hybrid
  16. Updating and Publishing a NuGet Package - Plus making NuGet packages smarter and avoiding source edits with WebActivator
  17. 微探eventlet.monkey_patch
  18. 018_nginx_proxy死循环问题
  19. DDL触发器(用来控制用户的DDL行为)
  20. Values & Reference:值和引用

热门文章

  1. classLoader双亲委托与类加载隔离
  2. Golang(十二)TLS 相关知识(三)理解并模拟简单代理
  3. 第27课 “共享状态”及其管理者(std::future/std::shared_future)
  4. postman使用的时候注意的坑
  5. Windows / Office - KMS激活
  6. Axure入门
  7. springboot mybatis使注解和xml两种方式同时生效
  8. laravel5.5框架中视图间如何共享数据?视图间共享数据的两种方法
  9. 『Pushbox 点双联通分量』
  10. MongoDB 学习笔记 ---创建用户