Product with tycho fails (starting a new process)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Product with tycho fails (starting a new process)

mort.motes
Not sure if this is the right forum but my problem only appears when I build my product with tycho.

In my code I run a windows bat file (which launches another java application) in a new process:

      new ProcessBuilder(pathTobatFile).start();

but the second process never starts when I run the product that is build with tycho.

If I build the product with PDE build (using the same target) the process is started just fine. So far I located the problem to be this line:

        handle = create(cmdstr, envblock, path, redirectErrorStream,
                        stdin_fd, stdout_fd, stderr_fd);


in the private constructor:

    private ProcessImpl(String cmd[],
                        String envblock,
                        String path,
                        boolean redirectErrorStream)
        throws IOException
    {

in the class java.lang.ProcessImpl.



Now when I debug the application build with PDE build the second application starts just after this line:


        handle = create(cmdstr, envblock, path, redirectErrorStream,
                        stdin_fd, stdout_fd, stderr_fd);

is executed which is:

    private native long create(String cmdstr,
                               String envblock,
                               String dir,
                               boolean redirectErrorStream,
                               FileDescriptor in_fd,
                               FileDescriptor out_fd,
                               FileDescriptor err_fd)

As I understand this calls some platform specific code. I know this is very technical stuff but any ideas to what might be causing the difference between application build with PDE build and tycho?
Reply | Threaded
Open this post in threaded view
|

Re: Product with tycho fails (starting a new process)

mort.motes
This is strange. If I call "getInputStream()" on the process and convert it to a String it works:

      ProcessBuilder processBuilder = new ProcessBuilder(pathTobatFile).start();
      // process.getInputStream() this is not enough!
      String resultString = convertStreamToString(process.getInputStream());

where:

  public String convertStreamToString(InputStream is) throws IOException {
    /*
     * To convert the InputStream to String we use the Reader.read(char[]
     * buffer) method. We iterate until the Reader return -1 which means there's
     * no more data to read. We use the StringWriter class to produce the
     * string.
     */
    if (is != null) {
      Writer writer = new StringWriter();
      char[] buffer = new char[1024];
      try {
        Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        int n;
        while ((n = reader.read(buffer)) != -1) {
          writer.write(buffer, 0, n);
        }
      } finally {
        is.close();
      }
      return writer.toString();
    } else {
      return "";
    }
  }

NOtice that its not enough to call "process.getInputStream()".

I can only reproduce this error when building with tycho. I will try and see if I can find some difference between tycho setup and pde build setup that relates to this error.

If anyone has any suggestion to what might contribute to this behavior please post!