我需要在java mapreduce程序中执行python脚本。
这里,在mapper类中,我需要执行python命令:
python methratio.py --ref=../refernce/referncefile -r -g --out=Ouputfile ./Inputfile
这里的输入文件是hdfs中的输入文件,输出文件(在hdfs中)是python脚本写入输出的地方。
我可以使用流程构建器还是其他更好的选项?
答案 0 :(得分:0)
我不知道这是否对您有所帮助,但您可以在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