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/例子的更多相关文章

  1. 【解决】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服务器提交 ...

  2. 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下载文件 ...

  3. 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 ...

  4. Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeException

    使用MapReduce编写的中文分词程序出现了 Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeExcept ...

  5. at org.apache.hadoop.util.RunJar.main(RunJar.java:153)

    关于手动编译hadoop入门例子WordCount并执行 之前做的例子都是用hadoop中已经编译好jar包来运行示例的但是这次想要手动编译个实例,练下手没想到还是遇到点了小困难 [root@cent ...

  6. 执行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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. C++分治策略实现二分搜索

    问题描述: 给定已排好序的n个元素组成的数组,现要利用二分搜索算法判断特定元素x是否在该有序数组中. 细节须知: (1)由于可能需要对分治策略实现二分搜索的算法效率进行评估,故使用大量的随机数对算法进 ...

  2. 最简单的 kubernetes 高可用安装方式

    sealos 项目地址:https://github.com/fanux/sealos 本文教你如何用一条命令构建 k8s 高可用集群且不依赖 haproxy 和 keepalived,也无需 ans ...

  3. 『optimization 动态规划』

    optimization Description \(visit\_world\) 发现有些优化问题可以用很平凡的技巧解决,所以他给你分享了这样一道题: 现在有一个长度为N的整数序列\(\{a_i\} ...

  4. mssql 根据执行计划细节做优化操作

    示例: 1.如果select * 通常情况下聚集索引会比非聚集索引更优. 2.如果出现Nested Loops,需要查下是否需要聚集索引,非聚集索引是否可以包含所有需要的列. 3.Hash Match ...

  5. 我是如何一步步编码完成万仓网ERP系统的(五)产品库设计 1.产品类别

    https://www.cnblogs.com/smh188/p/11533668.html(我是如何一步步编码完成万仓网ERP系统的(一)系统架构) https://www.cnblogs.com/ ...

  6. 3-RocketMQ 简单梳理 及 集群部署笔记

    原文:https://www.cnblogs.com/kevingrace/p/9015836.html 一.RocketMQ 基础知识介绍Apache RocketMQ是阿里开源的一款高性能.高吞吐 ...

  7. java虚拟机JVM基础

    (1)内存模型以及分区,需要详细到每个区放什么. 堆:Java虚拟机管理内存中最大的一块,线程共享区域.所有对象实例和数组都在堆上分配内存空间. 栈:线程私有,每个线程都会创建一个虚拟机栈,生命周期与 ...

  8. iis url 重写

    1.选择网站-找到有测url 重写 :2:选中它,在右上角有一个打开功能,点击打开 3.依然在右上角,点击添加规则 4:选择第一个,空白规则 名称随便输入,我们通常有这样一个需求,就是.aspx 后缀 ...

  9. 适合新手入门Spring Security With JWT的Demo

    Demo 地址:https://github.com/Snailclimb/spring-security-jwt-guide .欢迎 star! Spring Security 是Spring 全家 ...

  10. SpringMVC拦截器执行流程

    1:MyInterceptor1.MyInterceptor2这2个拦截器都放行 MyInterceptor1......preHandleMyInterceptor2......preHandle ...