2

我曾经编写PHP代码来执行pig命令,它运行良好,现在我切换到Java但似乎它不起作用,这是我的代码:

String pigCommand = "pig -x local -p ouput=/tmp my_pig_script.pig";

Runtime r = Runtime.getRuntime();
Process p;
int exitVal;

try {
    p = r.exec(pigCommand);
    exitVal = p.waitFor();
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = null;

    while((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br.close();

    System.out.println("exitVal: " + exitVal);
    System.out.println("Done");

如果我直接在控制台中运行那个 pig 命令,它可以工作,如果我用其他 shell 命令替换那个 Pig 命令说“ping www.yahoo.com”,并运行 java 程序,它也可以工作。那么可能是什么问题呢?谢谢

4

1 回答 1

0

您应该使用PigServer从 java 程序执行 pig 脚本。它更万无一失,更便携。

另请参阅此答案:https ://stackoverflow.com/a/11299259/373151

于 2013-03-04T17:14:54.163 回答