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 ...
随机推荐
- SpringCloud Ribbon 负载均衡 通过服务器名无法连接的神坑一个
一,问题 采取eureka集群.客户端通过Ribbon调用服务,Ribbon端报下列异常 java.net.UnknownHostException: SERVICE-HI java.lang.Ill ...
- Distributed and Parallel Computing
Omega Network Model
- 【前端知识体系-HTML相关】HTML基础知识强化总结
1.如何理解HTML? HTML类似于一份word"文档" 描述文档的"结构" 有区块和大纲 2.对WEB标准的理解? Web标准是由一系列标准组合而成.一个网 ...
- 微服务浅谈&服务治理的演变过程
这两天对互联网的架构演变进行了简单了解,并对微服务的出现很感兴趣,所以对相关知识进行了简单的整理与总结. 本篇文章先简单介绍了互联网架构的演变,进而介绍了服务化,最后介绍了微服务及最新的服务网格(Se ...
- Centos7/Ubuntu 初始化硬盘分区、挂载
刚刚在腾讯云买了一台服务器,刚买的服务器的数据盘都是需要自己来分区的,下面就记录一下操作. 通过命令fdisk-l查看硬盘信息 可以看到有两块硬盘/dev/vda和/dev/vdb,启动vda是系统盘 ...
- Java基础之UDP协议和TCP协议简介及简单案例的实现
写在前面的废话:马上要找工作了,做了一年的.net ,到要找工作了发现没几个大公司招聘.net工程师,真是坑爹呀.哎,java就java吧,咱从头开始学呗,啥也不说了,玩命撸吧,我真可怜啊. 摘要: ...
- .NetCore使用NLog写入数据库总结
考虑到项目后期添加日志的需求,抽个闲暇时间学习一下使用NLog插件将日志信息写入到数据库中,完整项目见下面: 遇到的问题: 使用NLog写到SQLServer里面的中文显示问号? 解决方法:调整数据库 ...
- Windows下Redis集群安装与部署
1.下载 Redis-x64-3.2.100.zip 安装程序 官网下载地址:http://redis.io/download GitHub下载地址:https://github.com/micros ...
- 视频监控GB28181测试参考
说明: 1. 需要对前端摄像机和后端NVR.解码器.平台进行GB28181测试和开发的人员.本文档提供的一些测试细节,比如测试环境,SIP消息格式说明,SDP文本信息字段说明,GB28181测试注意 ...
- 纯C语言实现线性链表
#include <stdio.h> #include <stdlib.h> typedef int ElemType; typedef struct LNode{ ElemT ...