在java映射redu中执行python脚本

2024-10-03 21:28:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要在javamapreduce程序中执行python脚本。在

这里,在mapper类中,我需要执行python命令:

 python methratio.py --ref=../refernce/referncefile -r -g --out=Ouputfile ./Inputfile

这里的Inputfile是hdfs中的输入文件,outputfile(在hdfs中)是python脚本编写输出的地方。在

是否可以使用process builder或其他更好的选项??在


Tags: 文件py命令程序脚本refhdfsout
1条回答
网友
1楼 · 发布于 2024-10-03 21:28:16

我不知道这是否对您有帮助,但您可以在java中以这种方式执行系统命令:

public static void main(String[] args) throws IOException {
        String s = null;
        String command = "python <your_command>";
        Process p = Runtime.getRuntime().exec(command);

    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

    // read the output from the command
    System.out.println("Here is the standard output of the command:\n");
    while ((s = stdInput.readLine()) != null) {
        System.out.println(s);
    }
}

您可以在http://alvinalexander.com/java/edu/pj/pj010016中看到一个详细的示例

希望这对你有帮助:D

相关问题 更多 >