title: C++ Save output of service in runtime
body: <p>I would like to collect output of service.exe to my c++ program (windows environment). In simple case there is call in cmd like "service.exe > log.txt" but in my case service is always shutdown by other system call "taskkill service.exe" that cause lack of output in log.txt.
  How can I solve this ? I try windows _popen but the same as simple system function call - lack of output in file.</p>
  
  <p>Code for example:</p>
  
  <pre><code>void test_of_runtime()
  {
  std::string result;
  
  /* Create path to service */
  boost::filesystem::path work_path(boost::filesystem::current_path());
  
  /* Run servie and save output in log file */
  work_path += "\\service.exe &gt; runtime_log.txt";
  
  /* Create another thread which terminate service after 10 seconds */
  boost::thread terminate_thread(terminate_thread_func);
  terminate_thread.detach();
  
  system(work_path.string().c_str());
  }
  
  
  
  void terminate_thread_func()
  {
  std::string terminate_command = "taskkill /F /T /IM service.exe";
  
  /* Wait 10 sec */
  boost::this_thread::sleep_for(boost::chrono::seconds(10));
  
  /* Terminate service after 10 sec */
  system(terminate_command.c_str());
  }
  </code></pre>