java吧 关注:1,232,233贴子:12,696,469
  • 1回复贴,共1

ProcessBuilder执行shell指令报错

只看楼主收藏回复

hadoop fs -put ./tmp/* /tmp
执行上述指令时,会出现如下错误:
put: `tmp/*': No such file or directory
若是直接指明文件路径,如:
hadoop fs -put ./tmp/1.txt /tmp
则能顺利执行。
求解!


IP属地:广东1楼2016-07-29 13:53回复
    使用的语言是scala,也就是对指令按空格分拆后,放进去执行
    def getCmd(cmd: String): java.util.List[String] = {
    import scala.collection.convert.wrapAsJava.bufferAsJavaList
    bufferAsJavaList(cmd.split(" ").filter(_ != "").toBuffer)
    }
    def exec_detail(cmd: String): (Array[String], Array[String]) = {
    import java.io.InputStreamReader
    import java.io.BufferedReader
    import scala.collection.mutable.ArrayBuffer
    val inputBuffer: ArrayBuffer[String] = ArrayBuffer()
    val errorBuffer: ArrayBuffer[String] = ArrayBuffer()
    try {
    val proc = new ProcessBuilder()
    val process = proc.command(getCmd(cmd)).start()
    val input = new BufferedReader(new InputStreamReader(process.getInputStream))
    val error = new BufferedReader(new InputStreamReader(process.getErrorStream))
    var line: String = input.readLine()
    while (line != null) {
    inputBuffer += line
    line = input.readLine()
    }
    input.close()
    line = error.readLine()
    while (line != null) {
    errorBuffer += line
    line = error.readLine()
    }
    error.close()
    } catch {
    case e: Throwable => e.printStackTrace()
    }
    (inputBuffer.toArray, errorBuffer.toArray)
    }


    IP属地:广东2楼2016-07-29 13:57
    回复