读书人

JAVA调用这个SHELL资料、为什么不能运

发布时间: 2012-09-14 23:00:49 作者: rapoo

JAVA调用这个SHELL文件、为什么不能运行
JAVA代码如下:
try {
Runtime rt = Runtime.getRuntime();

String str[] = {"/bin/sh", "-c", "/usr/hadoop-0.19.0/bin/load.sh"};

Process pcs = rt.exec(str);
BufferedReader br = new BufferedReader(new InputStreamReader(pcs.getInputStream()));
String line = new String();
if(textarea.getText()!=null)
textarea.setText("");
while ((line = br.readLine()) != null) {
textarea.append(line);
textarea.append("\n");

}
try {
pcs.waitFor();

} catch (InterruptedException e) {
System.err.println("processes was interrupted");
}
br.close();


} catch (Exception e) {
e.printStackTrace();
}

一个简单的Shell文件如下:
#!/bin/sh
bin/hadoop fs -mkdir input
bin/hadoop fs -put input1.txt input

不能正确运行shell文件,但是linux终端下面可以正确运行shell文件,本人是菜鸟,还望各位解答,谢谢。

读书人网 >编程

热点推荐