0
私はJavaでpythonを実行するためにランタイムとprocessbuilderの両方を試しましたが、javaはpythonの結果を表示できません。javaを使用してPythonを呼び出して実行しますが、結果は表示されません。 processbuilder runtime
のpythonコード:
def cal():
a=4
b=90
c=a+b
return c
if __name__ == "__main__":
c=cal()
print c
print "hello"
print "hello..................."
Javaコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class qqqqqqqqqqqqqqqq {
public static void main (String args[]) throws IOException {
try
{
// ProcessBuilder pb = new ProcessBuilder("C:/Python27/python","C://Users//admin//Destop//dsf.py");
// Process p = pb.start();
Runtime r=Runtime.getRuntime();
Process p=r.exec("cmd /c C:/Python27/python C://Users//admin//Destop//dsf.py");
BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println(".........start process.........");
String line = "";
while ((line = bfr.readLine()) != null)
{
System.out.println("Python Output: " + line);
}
System.out.println("........end process.......");
} catch (Exception e)
{
System.out.println(e);
}
}
}
Javaの出力結果:
.........start process.........
........end process.......
パスとコードにエラーがない、なぜJavaはパイソンを実行することはできません?