org.apache.hadoop.util.Shell demo/例子
2024-09-08 10:35:46
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);
最新文章
- Gradle 使用本地的Jar包(gradle oracle ojdbc14 )
- Elasticsearch——多索引的使用
- sublimetext
- DHU-1241 Oil Deposits
- python getpass模块:隐藏不显示输入的密码
- iOS 在下面 AOP 程序
- 禁止使用test类的就是禁止使用本来的$this对象.可以调用父类的对象
- 【转】CentOS 6.3(x86_64)下安装Oracle 10g R2
- HTML5详解(一)
- Codeforces Round #467 (div.2)
- 利用js实现 禁用浏览器后退
- CentOS 7 配置DHCP中继代理服务
- js获取当前页面的url网址信息小汇总
- IDEA安装Lombok插件失败的解决方案
- Native/Webview bridge for Hybrid
- Updating and Publishing a NuGet Package - Plus making NuGet packages smarter and avoiding source edits with WebActivator
- 微探eventlet.monkey_patch
- 018_nginx_proxy死循环问题
- DDL触发器(用来控制用户的DDL行为)
- Values &; Reference:值和引用
热门文章
- classLoader双亲委托与类加载隔离
- Golang(十二)TLS 相关知识(三)理解并模拟简单代理
- 第27课 “共享状态”及其管理者(std::future/std::shared_future)
- postman使用的时候注意的坑
- Windows / Office - KMS激活
- Axure入门
- springboot mybatis使注解和xml两种方式同时生效
- laravel5.5框架中视图间如何共享数据?视图间共享数据的两种方法
- 『Pushbox 点双联通分量』
- MongoDB 学习笔记 ---创建用户