简体   繁体   English

系统无法从Java找到指定的可执行文件

[英]The system cannot find the file specified executable from java

I have got a code which is stands for running an executable from java code. 我有一个代码,代表从Java代码运行可执行文件。 The program run smoothly until today. 该程序一直运行到今天。 I dont know what I have changed however I am receiving the following error: 我不知道自己做了什么更改,但是收到以下错误:

Cannot run program "\\Release\\program.exe" (in directory "I:\\Release\\"): CreateProcess error=2, The system cannot find the file specified 无法运行程序“ \\ Release \\ program.exe”(在目录“ I:\\ Release \\”中):CreateProcess错误= 2,系统找不到指定的文件

The code I am using is the following: 我使用的代码如下:

Process proc = rt.exec("Release\\program.exe", null, new File("I:\\Release\\"));

What could be the problem here? 这可能是什么问题? It used to work fine. 过去工作正常。

EDIT: Process proc = rt.exec("program.exe", null, new File("I:\\\\Release\\\\")); 编辑: Process proc = rt.exec("program.exe", null, new File("I:\\\\Release\\\\"));

I got the same error. 我遇到了同样的错误。 If I command from the explorer 如果我从资源管理器发出命令

> I:\\Release\\program.exe

this works fine 这很好

Assuming your folder structure looks like this: 假设您的文件夹结构如下所示:

I:\Release\program.exe

Your code would then have to look like this: 您的代码将必须如下所示:

Process proc = rt.exec("program.exe", null, new File("I:\\Release\\"));

EDIT: Try this instead: 编辑:试试这个代替:

ProcessBuilder proc = new ProcessBuilder("I:\\Release\\program.exe");
proc.start();

Can you try this ? 你可以试试这个吗?

// Java runtime
Runtime runtime = Runtime.getRuntime();
// Command
String command = "I:/Release/program.exe" ;
// Process
Process process = runtime.exec(command, null, new File("I:/Release"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM