org.apache.hadoop.util.Shell demo/例子
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);
org.apache.hadoop.util.Shell demo/例子的更多相关文章
- 【解决】org.apache.hadoop.util.Shell$ExitCodeException: /bin/bash: line 0: fg: no job control
[环境信息] Hadoop版本:2.4.0 客户端OS:Windows Server 2008 R2 服务器端OS:CentOS 6.4 [问题现象] 在通过Windows客户端向Linux服务器提交 ...
- java.lang.NullPointerException at java.lang.ProcessBuilder.start(Unknown Source) at org.apache.hadoop.util.Shell.runCommand(Shell.java:482)
1:问题出现的原因,部署好的hadoop-2.6.4进行window10操作hadoop api出现的错误,具体错误是我向hdfs上传文件,还好点,之前解决过,这里不叙述,这里说一下从hdfs下载文件 ...
- ERROR [org.apache.hadoop.util.Shell] - Failed to locate the winutils binary in the hadoop binary path
错误日志如下: -- ::, DEBUG [org.apache.hadoop.metrics2.lib.MutableMetricsFactory] - field org.apache.hadoo ...
- Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeException
使用MapReduce编写的中文分词程序出现了 Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeExcept ...
- at org.apache.hadoop.util.RunJar.main(RunJar.java:153)
关于手动编译hadoop入门例子WordCount并执行 之前做的例子都是用hadoop中已经编译好jar包来运行示例的但是这次想要手动编译个实例,练下手没想到还是遇到点了小困难 [root@cent ...
- 执行Hive时出现org.apache.hadoop.util.RunJar.main(RunJar.java:136) Caused by: java.lang.NumberFormatException: For input string: "1s"错误的解决办法(图文详解)
不多说,直接上干货 问题详情 [kfk@bigdata-pro01 apache-hive--bin]$ bin/hive Logging initialized -bin/conf/hive-log ...
- Exceptionin thread "main" java.lang.UnsatisfiedLinkError:org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(II[BI[BIILjav
在eclipse上运行hadoop报错:Exceptionin thread "main" java.lang.UnsatisfiedLinkError:org.apache.ha ...
- hadoop错误org.apache.hadoop.util.DiskChecker$DiskErrorException Could not find any valid local directory for
错误: org.apache.hadoop.util.DiskChecker$DiskErrorException: Could not find any valid local directory ...
- win7上代码连接hadoop出现错误 :org.apache.hadoop.util.NativeCrc32.nativeComputeChunkedSumsByteArray(II[BI[BIILjava/lang/String;JZ)V
在idea和eclipse中调试hadoop中hdfs文件,之前好好的,结果突然就出现java.lang.UnsatisfiedLinkError: org.apache.hadoop.util.Na ...
随机推荐
- App启动时间分析
iOS应用的启动可分为pre-main阶段和main()阶段. 1.pre-main阶段 可以通过配置Scheme,设置DYLD_PRINT_STATISTICS为1,来打印pre-main阶段的时间 ...
- c# linq分组 lambda分组
var groupResults = from gr in models && gr.Temperature != && gr.Humidity != &&am ...
- SQLserver 存储过程游标使用
ALTER PROCEDURE [dbo].[p_DeleteStretchData] ) , ) AS BEGIN ) ) declare @stretch_cursor cursor -- 声明游 ...
- Docker remote API
Docker remote API 该教程基于Ubuntu或Debian环境,如果不是,请略过本文 Docker API 在Docker生态系统中一共有三种API Registry API:提供了与来 ...
- ng使用bootstrap
1.在项目中使用命令 npm i bootstrap -s来创建bootstrap 2.创建完成之后在 angular.json中引入进去 "styles": [ ...
- Redis学习之Redis服务器数据库实现
本文内容: 1.Redis服务器保存数据库的方法 2.客户端切换数据库的方法 3.数据库保存键值对的方法 4.数据库的添加,删除,查看,更新操作的实现方法 5.服务器保存键的过期时间的方法 6.服务器 ...
- R语言dai xie
R语言,Python长期招代写,作业量充足,需要一定英文能力,价格满意.有意者请留言联系,谢谢
- 一、hexo+github搭建个人博客的过程记录
前提: 1.新建一个github仓库 2.安装配置Node.js 3.安装配置Git 前提 步骤1.新建一个github仓库 打开github网站,(注册)登录账号,新建一个仓库; 注:==仓库名称要 ...
- mybatis分页的一种解决方案
mybatis自定义分页解决方案 1.PageSqlProvider<T> —— 提供默认的分页列表查询 package com.xinyartech.erp.core.base; im ...
- Barrier 组织多个线程及时在某个时刻碰面
任意一个线程调用了 _barrier.SignalAndWait() 方法后,会执行一个回调函数来打印出阶段. /// <summary> /// 实例 Barrier 类 /// < ...