从java throws调用python文件

2024-09-24 04:21:34 发布

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

我试图从java调用python文件。但它抛出了以下错误。在

java.io.IOException: Cannot run program "python": CreateProcess error=2, The system cannot find the file specified

我尝试过的代码是:

^{pr2}$

有什么问题吗?在


Tags: 文件therunio错误errorjavafind
1条回答
网友
1楼 · 发布于 2024-09-24 04:21:34

在运行时.exec不包含路径信息的文件应位于用户目录中,而不在指定用作工作目录的目录中。 尝试使用此代码一次。在

Runtime rt = Runtime.getRuntime();
Process prs;
File Dir_temp = new File("C:\\Project\\Script\\");
prs = rt.exec(new File(Dir_temp, "Test.py").getAbsolutePath(), null, Dir_temp);
prs.waitFor();
prs.destroy();

相关问题 更多 >