title: Getting IOException while using camel exec component to invoke a batch file
body: <p>I am using a basic implementation of <a href="http://camel.apache.org/exec.html" rel="nofollow">camel's exec component</a> to invoke a batch file in a windows environment. Whenever the batch file execution fails and it returns non zero exit code along with some error message, my routes work just fine. But whenever the execution is successful, it throw IOException as follows.</p>
  
  <pre><code>org.apache.camel.component.exec.ExecException: Unable to execute command ExecCommand [args=[/C, d:\file.bat, test_request.xml, null], executable=cmd, timeout=5000, outFile=null, workingDir=null, useStderrOnEmptyStdout=false]
  at org.apache.camel.component.exec.impl.DefaultExecCommandExecutor.execute(DefaultExecCommandExecutor.java:81)
  at org.apache.camel.component.exec.ExecProducer.process(ExecProducer.java:46)
  at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
  at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)
  at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
  at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
  at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
  at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
  at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
  at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
  at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:150)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
  at org.eclipse.jetty.server.Server.handle(Server.java:366)
  at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
  at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)
  at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)
  at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
  at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
  at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
  at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
  at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
  at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
  at java.lang.Thread.run(Unknown Source)
  Caused by: java.io.IOException: Stream Closed
      at java.io.FileOutputStream.writeBytes(Native Method)
      at java.io.FileOutputStream.write(Unknown Source)
      at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
      at java.io.BufferedOutputStream.flush(Unknown Source)
      at java.io.FilterOutputStream.close(Unknown Source)
      at org.apache.commons.exec.DefaultExecutor.closeStreams(DefaultExecutor.java:288)
      at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:364)
      at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
      at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
      at org.apache.camel.component.exec.impl.DefaultExecCommandExecutor.execute(DefaultExecCommandExecutor.java:67)
      ... 30 more
  </code></pre>
  
  <p>Strangely enough, whenever i run my jar from inside the eclipse IDE, everything works just fine. But whenever i deploy it from command prompt using "java -jar", it gives me the above stated exception only in case when the batch file processing is completed successfully. Doing a lot of research gives me an idea that this problem has something to do with the streams that java runtime uses, but i am unable to get to the root cause. I tried providing the out file using ExecBinding.EXEC_COMMAND_OUT_FILE in camel exec but that didn't solved my problem.  </p>