我有一个python文件,它打开了一个带有硒的网页。如何在 java 应用程序中运行此文件?我尝试了Runtime((.exec("python main.py"(和"python3 main.py",但它不起作用。
使用 ProcessBuilder。
String[] commands = { "python", "main.py" }; // Need to add a python or python3 to the system path
ProcessBuilder pb = new ProcessBuilder(commands);
pb.directory("Set the path of the main.py folder");
Process proc = pb.start();