title: Process is not terminating Properly in java (Runtime)
body: <p>I am executing CSharp Program with java Process by creating the .exe file but the process of that file is not responding with 0 <code>exitCode</code>.Errors are Empty.In Visual Studio it runs fine but with java, it creates problem.No output and no Errors, I am stuck in this Please help. I am using Java 7.
  I am using <code>Csc (inbuild compiler in .Net framework for windows)</code> It is giving me <code>dll</code> reference error.Command is following</p>
  
  <pre><code>csc /nologo /r:D:/simulatorConfig/ArrayConversion.dll /out:D:\\apache-tomcat-7.0.64\\temp\\tmp749792186557790590.exe D:\\apache-tomcat-7.0.64\\temp\\tmp749792186557790590.cs
  
  stream = new BufferedReader(new InputStreamReader(proc.getErrorStream())); 
  </code></pre>
  
  <p>above is Error which is empty String.</p>
  
  <p>code is here Please look at it.</p>
  
  <pre><code>public File compile(File sourceFile, LANGUAGE lang) throws InterruptedException, IOException, CompilerException, ConfigurationException {
      String absolutePath = sourceFile.getCanonicalPath();
      // System.out.println("absolutePath : " + absolutePath);
      String destFile;
      if (OsUtils.isWindows()) {
          destFile = absolutePath.replace(lang.getFileExtension(), EXECUTABLE_FILE_SUFFIX);
      } else {
          destFile = absolutePath.replace(lang.getFileExtension(), "");
      }
  
      String compileCommand = generateCommand(absolutePath, destFile, lang);
      logger.error("compileCommand : " + compileCommand);
      // Compiles and create exe file for execution
      Process proc = Runtime.getRuntime().exec(compileCommand);
  
      // Wait for process to complete
      int returnValue = proc.waitFor();
  
      if (returnValue != 0) {
          String errorMsg = getCompilerMessage(sourceFile, proc, lang);
          throw new CompilerException(errorMsg);
      }
  
      proc.destroy();
  
      return new File(destFile);
  }
  
  private String getCompilerMessage(File sourceFile, Process proc, LANGUAGE lang) throws IOException {
  
      StringBuilder message = new StringBuilder();
      BufferedReader stream = null;
      String line = null;
  
      switch (lang) {
      case C:
      case CPP:
          // GNU C/CPP compiler prints compiler errors in standard errors
          // tream
          stream = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
          break;
  
      case CSHARP:
          // CSharp compiler prints compiler errors in standard output stream
          stream = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
          break;
  
      }
  
      while ((line = stream.readLine()) != null) {
          logger.error(line);
          line = line.substring(line.indexOf(sourceFile.getName()) + (int) sourceFile.getName().length());
          if (message.toString().isEmpty()) {
              message.append(lang == LANGUAGE.CSHARP ? "Line" : "").append(line);
          } else {
              message.append("&lt;br/&gt;Line").append(line);
          }
          // message.append(line).append(SystemUtils.LINE_SEPARATOR);
      }
  
      stream.close();
  
      return message.toString();
  }
  
  private String generateCommand(String sourceFile, String destFile, LANGUAGE lang) throws ConfigurationException {
      // System.out.println("sourceFile : " + sourceFile + " -- destFile : " +
      // destFile);
      Configuration config = new PropertiesConfiguration("system.properties");
      String cmd = "";
      switch (lang) {
      case C:
      case CPP:
          sourceFile = sourceFile.replace("\\", "\\\\");
          destFile = destFile.replace("\\", "\\\\");
          cmd = "g++ " + sourceFile + " -o " + destFile + " " + config.getString("C_CPP_HEADERFILE").trim();
          break;
  
      case CSHARP:
          sourceFile = sourceFile.replace("\\", "\\\\");
          destFile = destFile.replace("\\", "\\\\");
          logger.error("Config Path : "+config.getString("MONO_PATH"));
          if (OsUtils.isWindows()) {
              cmd = "csc /nologo /r:" + config.getString("CS_HEADERFILE_WIN") + " /out:" + destFile + " " + sourceFile;
          } else {
              cmd = "/opt/mono/bin/mcs /reference:" + config.getString("CS_HEADERFILE") + " /out:" + destFile + " "
                      + sourceFile;
          }
  
          break;
      }
      logger.info("Command :" + cmd);
      return cmd;
  }
  </code></pre>