如何启动脚本(.sh或.bat)vai boost进程?

时间:2011-10-28 21:12:22

标签: c++ boost process

我想知道是否有可能以及如何通过升级过程在Windows上启动.bat或在Linux脚本上启动.sh?

1 个答案:

答案 0 :(得分:1)

启动批处理文件的示例:

#include <boost/process.hpp> 
#include <string> 
#include <iostream> 

using namespace boost::process; 

int main() 
{ 
  context ctx; 
  ctx.environment = self::get_environment(); 
  child c = launch("cmd", "/c batch.bat", ctx); 
  status s = c.wait(); 
  if (s.exited()) 
    std::cout << s.exit_status() << std::endl; 
} 

未测试。关键是使用/ c

将批处理文件传递给cmd