无法运行 c/c++ Eclipse RCP 中的 exe
我正在尝试从 eclipse RCP
(Java API)运行我的 c/c++.exe
。
代码:
package com.jkt.rcp.texteditor.handlers;
import java.io.IOException;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
//import com.jkt.runner.utils.Test;
public class RecordHandler extends AbstractHandler {
private RecordingThread recordingThread;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("inside RecordHandler...");
recordingThread = new RecordingThread();
recordingThread.start();
return null;
}
}
RecordingThread.java
的代码是:
package com.jkt.rcp.texteditor.handlers;
import java.io.IOException;
public class RecordingThread extends Thread {
private String file = "C:\\workspace\\JProAcceptanceBot\\Record.exe";
public void run() {
System.out.println("inside Run()...");
try {
Process proc = Runtime.getRuntime().exec(file);
} catch (IOException e) {
System.out.println("IOException:"+e);
e.printStackTrace();
}
}
}
实际上,RecordHandler.java
在单击 eclipse RCP
按钮后执行。
但是,一旦我单击按钮,c/c++ exe
就没有响应,我的 Java 程序也停止响应。
否则,如果我在 Eclipse 中运行此 exe,它会正常运行。
这个c/c++ exe
是使用Eclipse CDT和Cygwin制作的。
请查看代码并提出建议?
I am trying to run my c/c++ .exe
from eclipse RCP
(Java API).
Code:
package com.jkt.rcp.texteditor.handlers;
import java.io.IOException;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
//import com.jkt.runner.utils.Test;
public class RecordHandler extends AbstractHandler {
private RecordingThread recordingThread;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("inside RecordHandler...");
recordingThread = new RecordingThread();
recordingThread.start();
return null;
}
}
And code of RecordingThread.java
is:
package com.jkt.rcp.texteditor.handlers;
import java.io.IOException;
public class RecordingThread extends Thread {
private String file = "C:\\workspace\\JProAcceptanceBot\\Record.exe";
public void run() {
System.out.println("inside Run()...");
try {
Process proc = Runtime.getRuntime().exec(file);
} catch (IOException e) {
System.out.println("IOException:"+e);
e.printStackTrace();
}
}
}
Actually RecordHandler.java
executes after clicking a eclipse RCP
button.
But as soon as I click button, c/c++ exe
doesn't respond and my Java program stops responding.
Otherwise if I run this exe
inside my eclipse, it runs fine.
This c/c++ exe
has been made by using Eclipse CDT and Cygwin.
Please have a look into code and suggest ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意 Sun bug 6468220(另请参阅 bug 6550942 和 bug 6511002):
在 Windows 平台上,如果其中一个参数包含双引号 ("),则 Runtime.exec(String[] cmdarray) 无法正确传递命令行参数。
所以我的问题是:您尝试执行的确切命令行是什么?
Be aware of Sun bug 6468220 (also described in bug 6550942 and bug 6511002):
On Windows platform Runtime.exec(String[] cmdarray) does not pass correctly command line arguments, if one of them contains double quotes (").
So my question is: what is the exact command line you are trying to execute?
我不确定,但您可能想立即开始读取通过 proc.GetInputStream() 获取的 proc 输入流。 在
Process 的文档中
:
这篇关于 javaworld 的文章 描述了相同的问题并解释了解决方案(第 3 页)。
I'm not sure, but you might want to immediately start reading the inputstream of
proc
obtained through proc.GetInputStream(). In the documentation forProcess
:This article on javaworld describes the same problem and explains the solution (on page 3).