title: How to correctly run a .bat file from java under a windows service?
body: <p>From my java project I want to run an external .bat file in another thread. For this purpose I use the following method:</p>
  
  <pre><code>    private void posAppRunner(final String path[], final Class targetClass) {
      new Thread(new Runnable() {
          public void run() {
              try {
                  String line;
                  Process p = Runtime.getRuntime().exec(path);
                  BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                  while ((line = input.readLine()) != null) {
                      System.out.println(line);
                  }
                  input.close();
              } catch (IOException e) {
                  LogFactory.getLog(targetClass).warn("Error when starting a PosApplication: " + e.getMessage());
              }
          }
  
      }).start();
  </code></pre>
  
  <p>I run the following .bat file:</p>
  
  <pre><code>call chdir %~dp0
  
  start java &lt;_some_arguments&gt;
  </code></pre>
  
  <p>So when I do it locally from IntelliJ IDEA it works correct - a cmd process appears, after that a java process appears and after that the cmd process disappears.</p>
  
  <p>But when I run my java project  with this method through ANT under TeamCity windows service, only cmd process appears and nothing happens after. Java process that must be started from the bat file doesn't appear. It looks like I don't read the process output but I do!</p>
  
  <p>Could you expain me, how to overcome this situation?</p>