我需要使用Java代码运行Python 3脚本

时间:2017-05-17 21:55:14

标签: java python-3.x

我有以下Java代码片段,它适用于Python 2兼容脚本。但是,当我使用Java使用Python 3兼容脚本时,我没有得到任何输出。

String[] cmd = {
                python,
                file.getAbsolutePath(),
                };
String[] envCommand = {"source activate root"}; //My root environment is having python3, 

Runtime runtime = Runtime.getRuntime();
process = runtime.exec(cmd, envCommand);
readOutputFromPythonProcess(process);

1 个答案:

答案 0 :(得分:0)

当你使用exec时,一定要将python设置为MERGE INTO tableUser t USING (VALUES('name',91,'9811223344','a@b.com',1)) s(name, countryCode, mobile, email, ip) ON t.email = s.email WHEN NOT MATCHED THEN INSERT (name, countryCode, mobile, email, ip) values(s.name,s.countryCode,s.mobile,s.email,s.ip) WHEN MATCHED THEN UPDATE set ip = t.ip /* No change */ OUTPUT inserted.ID; ,并且还要为脚本提供的任何错误读取错误流