无法运行 c/c++ Eclipse RCP 中的 exe

发布于 2024-08-14 07:06:41 字数 1542 浏览 3 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无声静候 2024-08-21 07:06:42

请注意 Sun bug 6468220(另请参阅 bug 6550942bug 6511002):

在 Windows 平台上,如果其中一个参数包含双引号 ("),则 Runtime.exec(String[] cmdarray) 无法正确传递命令行参数。

Passing/Expected           --> Actual

{ "ab\"c", "d\"ef" }       --> { "abc def" }
{ "a b \" c", "d \" e f" } --> { "a b ", "c d", "e f " }
{ "a", "", "b" }           --> { "a", "b" }
{ "\" a" }                 -->     java.lang.IllegalArgumentException

所以我的问题是:您尝试执行的确切命令行是什么?

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 (").

Passing/Expected           --> Actual

{ "ab\"c", "d\"ef" }       --> { "abc def" }
{ "a b \" c", "d \" e f" } --> { "a b ", "c d", "e f " }
{ "a", "", "b" }           --> { "a", "b" }
{ "\" a" }                 -->     java.lang.IllegalArgumentException

So my question is: what is the exact command line you are trying to execute?

爱殇璃 2024-08-21 07:06:41

我不确定,但您可能想立即开始读取通过 proc.GetInputStream() 获取的 proc 输入流。 Process 的文档中

其所有标准 io(即 stdin、
stdout、stderr)操作将是
重定向到父进程
通过三个溪流
(进程.getOutputStream(),
Process.getInputStream(),
Process.getErrorStream())。家长
过程使用这些流来供给
输入并从中获取输出
子进程。 因为有些本土
平台仅提供有限的缓冲
标准输入和输出的大小
流,未能及时写入
输入流或读取输出流
子进程可能会导致
子进程阻塞,甚至
陷入僵局。

这篇关于 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 for Process:

All its standard io (i.e. stdin,
stdout, stderr) operations will be
redirected to the parent process
through three streams
(Process.getOutputStream(),
Process.getInputStream(),
Process.getErrorStream()). The parent
process uses these streams to feed
input to and get output from the
subprocess. Because some native
platforms only provide limited buffer
size for standard input and output
streams, failure to promptly write the
input stream or read the output stream
of the subprocess may cause the
subprocess to block, and even
deadlock.

This article on javaworld describes the same problem and explains the solution (on page 3).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文