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. vue组件component没效果

    如果实在不知道问题所在,你就看看你的component的命名是不是驼峰命名

  2. 1小时搞定vuepress快速制作vue文档/博客+免费部署预览

    先来一下演示效果.和vue的官方文档几乎是一致的,页面内容都可自定义. 此教程部署后的效果预览. 在你跟着教程搭建好项目之后,你会收获: 快速搭建一个文档/博客,后期只需要修改markdown内容和导 ...

  3. C# while循环

    一.简介 只要给定条件为true,C#的while循环语句会循环重新执行一个目标的语句. 二.语法 C# while的语法: while(循环条件) { 循环体: } 三.执行过程 程序运行到whil ...

  4. jQuery实现C#CheckBoxList模糊搜索

    前言 最近开发的一套系统中需要对商品进行管理,在选择商品时,要分别从品牌.型号.商品三个类别分别选择对应的选项才能找到需要的商品,三者的关系为:品牌包含型号,型号包含商品,因此使用了三个不同的 asp ...

  5. MD5加密方法HashPasswordForStoringInConfigFile(string,string)过时问题处理方法

    最近写代码的时候一直有一种很奇怪的感觉,查了一下发现原来是系统中的MD5加密方法报了过时的警告,虽然对系统没有任何影响,但是开发过程中绿色波浪线就像挥之不去的阴影一样.开发人员多多少少都会有点强迫症, ...

  6. 正则表达式(RegEx)官方手册/权威指南【Python】

    前言 正则表达式(称为RE,或正则,或正则表达式模式)本质上是嵌入在Python中的一种微小的.高度专业化的编程语言,可通过 re 模块获得. 使用这种小语言,你可以为要匹配的可能字符串集指定规则:此 ...

  7. Spring扩展点之BeanPostProcessor

    前言 BeanPostProcessor接口是Spring中一个非常重要的接口,它的接口定义如下 public interface BeanPostProcessor { Object postPro ...

  8. Eureka2.0集群环境

    当有2个eureka注册中心构建eureka注册中心集群时,1:微服务的注册中心地址要写2个eureka注册中心的地址,以逗号分隔2:其中1个eureka注册中心A保留有微服务的注册信息,作为主注册中 ...

  9. SAP CRM Product Interlinkage - Customer Product ID的一个例子

    For detail technical introduction about relationship, please refer to this wiki. The relationship tr ...

  10. Go语言学习——三分钟看透iota

    源起枚举 最近做需求时,有一个需要枚举的场景,大概有10+个枚举类型,不愿意像定义一个开关那样敷衍的写成 const ( SwitchOff = 0 SwitchOn = 1 ) 显得不够精致~ 于是 ...