0

I am trying to start a Windows Forms application from Java (eclipse rcp plugin) using the following code.

// locate resource in plugin
Bundle bundle = Platform.getBundle("com.acme.devicewebservice");
URL url = FileLocator.find(bundle, new Path("dotnet"), null);
url = FileLocator.resolve(url);
File f = new File(url.toURI());
if(f.isDirectory())
{
    // start app
    File prg = new File(f, "MyApp.exe");                
    ProcessBuilder pb = new ProcessBuilder(prg.getAbsolutePath(), "-port", "8081");
    pb.directory(f);
    pb.environment().put("PATH", f.getAbsolutePath());
    process = pb.start();
}

The process starts but the application does not appear.

If I start notepad.exe then the Notepad appears.

    ProcessBuilder pb = new ProcessBuilder("notepad.exe");

If I start the application using cmd that works to but I never get the Process object of my app.

    ProcessBuilder pb = new ProcessBuilder("cmd", "/C", "start", prg.getAbsolutePath());

Is this a problem with Java or with the Windows application? I have the sources for both.

Update The above app is an eclipse rich client. I tried starting the process from a simple Java app and this works. I then tried starting it from a simple SWT app and this works too. Now wondering what is different with a rich client app...

paul
  • 13,312
  • 23
  • 81
  • 144
  • does your application appear when you run it from the command line? – Zoltán Mar 10 '15 at 13:16
  • Investigate/debug wether MyApp.exe immediately exits because some precondition is wrong, e.g. it doesn't have permission to write stuff in its current working directory, or the ""-port", "8081" means it tries to bind or connect to port 8081 which fails or similar. Is the process visible in the task manager ? – nos Mar 10 '15 at 13:19
  • @Zoltán - yes. I can start the app directly and it works. A window appears. – paul Mar 10 '15 at 13:27
  • @nos - yes. The process does appear in the task manager but does not appear as a window. The process lives until the Java app ends. – paul Mar 10 '15 at 13:28
  • 4
    You could read the standard output or error output of the process, maybe that will tell you something. See for example http://stackoverflow.com/questions/16714127/how-to-redirect-process-builders-output-to-a-string on how to do this – David ten Hove Mar 10 '15 at 13:32
  • 2
    Did you try building another "MyApp.exe" with just a "Hello World"-Window? If that works, you can go an look for differences. – Fildor Mar 10 '15 at 13:39
  • @DavidtenHove - done that. Nothing – paul Mar 11 '15 at 05:52
  • @Fildor - done that. The process appears in the task manager but no window appears – paul Mar 11 '15 at 05:53

0 Answers0