【问题标题】:How to launch a script (.sh or .bat) vai boost process?如何启动脚本(.sh 或 .bat)vai boost 进程?
【发布时间】:2011-10-28 21:12:22
【问题描述】:

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

【问题讨论】:

    标签: c++ boost process


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多