Vishal
Vishal

Reputation: 159

Unable to run c/c++ exe from eclipse RCP

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 ?

Upvotes: 1

Views: 1115

Answers (2)

jilles de wit
jilles de wit

Reputation: 7138

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

Upvotes: 1

VonC
VonC

Reputation: 1324168

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?

Upvotes: 0

Related Questions