当前位置: 首页>>代码示例>>C++>>正文


C++ ACE_Process_Options::working_directory方法代码示例

本文整理汇总了C++中ACE_Process_Options::working_directory方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Process_Options::working_directory方法的具体用法?C++ ACE_Process_Options::working_directory怎么用?C++ ACE_Process_Options::working_directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ACE_Process_Options的用法示例。


在下文中一共展示了ACE_Process_Options::working_directory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: r

int
launcher_rvgl::_launch(const std::string &host_id) {
    if (_running) return err_already_running;

    std::string dir = pref()->get<std::string>("advanced/rvgl_path", "");
    std::string params = pref()->get<std::string>("advanced/rvgl_cmdline", "");

    if (dir.empty()) {
        win_registry r(win_registry::id_dplay, "", "Re-Volt");
        dir = r.get<std::string>("Path", "");
        pref()->set("advanced/rvgl_path", dir.c_str());
    }

    std::string cmd(dir);
#ifdef WIN32
    cmd += "/rvgl.exe";
#else
    cmd += "/rvgl";
#endif
    cmd = "\"" + cmd + "\"";
    if (!params.empty()) cmd += " " + params;
    cmd += (host_id.empty() ? " -lobby" : " -lobby " + host_id);

    //printf("%s\n", cmd.c_str());
    ACE_DEBUG((LM_DEBUG, "launcher_rvgl: command line: %s\n",
              cmd.c_str()));

    // Launch options
    ACE_Process_Manager *pm = ACE_Process_Manager::instance();
    ACE_Process_Options opts;
    opts.working_directory(dir.c_str());
    opts.command_line(cmd.c_str());
    _rvgl_pid = pm->spawn(opts, this);
    ACE_DEBUG((LM_INFO, "launcher_rvgl: pid %d from thread %t, cmd: %s\n",
               _rvgl_pid, cmd.c_str()));
    if (_rvgl_pid == ACE_INVALID_PID) {
        ACE_ERROR((LM_ERROR, "launcher_rvgl: failed to launch: %s\n",
                  cmd.c_str()));
        return err_could_not_launch;
    }
    
    _running = true;
    
    return 0;
}
开发者ID:ajalkane,项目名称:rvhouse,代码行数:45,代码来源:launcher_rvgl.cpp

示例2: main

int main(int argc, char *argv[])
{
    ACE_Process_Options options;
    FILE *fp = 0;
    char *n_env = 0;
    int n;

    if (argc == 1) {
        n_env = ACE_OS::getenv("FACTORIAL");
        n = n_env == 0 ? 10 : atoi(n_env);
        options.command_line("%s %d", argv[0], n - 1);
        const char *working_dir = ACE_OS::getenv("WORKING_DIR");
        if (working_dir) options.working_directory(working_dir);
        fp = fopen("factorial.log", "a");
        cout << "before setenv" << endl;
        options.setenv("PROGRAM=%s", ACE::basename(argv[0]));
        cout << "after setenv" << endl;
    } else {
        fp = fopen("factorial.log", "a");
        if (atoi(argv[1]) == 1) {
            fprintf(fp, "[%s|%d]: base case\n",
                    ACE_OS::getenv("PROGRAM"), ACE_OS::getpid());
            fclose(fp);
            return 1;
        } else {
            n = atoi(argv[1]);
            options.command_line("%s %d", argv[0], n - 1);
        }
    }

    ACE_Process child;
    child.spawn(options);
    child.wait();
    int factorial = n * child.return_value();
    fprintf(fp, "[%s|%d]: %d! == %d\n",
            ACE_OS::getenv("PROGRAM"), ACE_OS::getpid(),
            n, factorial);
    fclose(fp);
    return factorial;
}
开发者ID:chenjianlong,项目名称:books-code,代码行数:40,代码来源:process_factorial2.cpp

示例3: if

pid_t
ACE_Process::spawn (ACE_Process_Options &options)
{
  if (this->prepare (options) < 0)
    return ACE_INVALID_PID;

  // Stash the passed/duped handle sets away in this object for later
  // closing if needed or requested. At the same time, figure out which
  // ones to include in command line options if that's needed below.
  ACE_Handle_Set *set_p = 0;
  if (options.dup_handles (this->dup_handles_))
    set_p = &this->dup_handles_;
  else if (options.passed_handles (this->handles_passed_))
    set_p = &this->handles_passed_;

  // If we are going to end up running a new program (i.e. Win32, or
  // NO_EXEC option is set) then get any handles passed in the options,
  // and tack them onto the command line with +H <handle> options,
  // unless the command line runs out of space.
  // Note that we're using the knowledge that all the options, argvs, etc.
  // passed to the options are all sitting in the command_line_buf. Any
  // call to get the argv then splits them out. So, regardless of the
  // platform, tack them all onto the command line buf and take it
  // from there.
  if (set_p && !ACE_BIT_ENABLED (options.creation_flags (),
                                 ACE_Process_Options::NO_EXEC))
    {
      int maxlen = 0;
      ACE_TCHAR *cmd_line_buf = options.command_line_buf (&maxlen);
      size_t max_len = static_cast<size_t> (maxlen);
      size_t curr_len = ACE_OS::strlen (cmd_line_buf);
      ACE_Handle_Set_Iterator h_iter (*set_p);
      // Because the length of the to-be-formatted +H option is not
      // known, and we don't have a snprintf, guess at the space
      // needed (20 chars), and use that as a limit.
      for (ACE_HANDLE h = h_iter ();
           h != ACE_INVALID_HANDLE && curr_len + 20 < max_len;
           h = h_iter ())
        {
#if defined (ACE_WIN32)
# if defined (ACE_WIN64)
          curr_len += ACE_OS::sprintf (&cmd_line_buf[curr_len],
                                       ACE_TEXT (" +H %I64p"),
                                       h);
# else
          curr_len += ACE_OS::sprintf (&cmd_line_buf[curr_len],
                                       ACE_TEXT (" +H %p"),
                                       h);
# endif  /* ACE_WIN64 */
#else
          curr_len += ACE_OS::sprintf (&cmd_line_buf[curr_len],
                                       ACE_TEXT (" +H %d"),
                                       h);
#endif /* ACE_WIN32 */
        }
    }

#if defined (ACE_HAS_WINCE)
  // Note that WinCE does not have process name included in the command line as argv[0]
  // like other OS environment.  Therefore, it is user's whole responsibility to call
  // 'ACE_Process_Options::process_name(const ACE_TCHAR *name)' to set the proper
  // process name (the execution file name with path if needed).
  BOOL fork_result =
    ACE_TEXT_CreateProcess (options.process_name(),
                            options.command_line_buf(),
                            options.get_process_attributes(),  // must be NULL in CE
                            options.get_thread_attributes(),   // must be NULL in CE
                            options.handle_inheritance(),      // must be false in CE
                            options.creation_flags(),          // must be NULL in CE
                            options.env_buf(),                 // environment variables, must be NULL in CE
                            options.working_directory(),       // must be NULL in CE
                            options.startup_info(),            // must be NULL in CE
                            &this->process_info_);

  if (fork_result)
    {
      parent (this->getpid ());
      return this->getpid ();
    }
  return ACE_INVALID_PID;

#elif defined (ACE_WIN32)
  void* env_buf = options.env_buf ();
  DWORD flags = options.creation_flags ();
# if defined (ACE_HAS_WCHAR) && !defined (ACE_USES_WCHAR)
  wchar_t* wenv_buf = 0;
  if (options.use_unicode_environment ())
    {
      wenv_buf = this->convert_env_buffer (options.env_buf ());
      env_buf = wenv_buf;
      flags |= CREATE_UNICODE_ENVIRONMENT;
    }
# endif

  BOOL fork_result =
    ACE_TEXT_CreateProcess (0,
                            options.command_line_buf (),
                            options.get_process_attributes (),
                            options.get_thread_attributes (),
                            options.handle_inheritance (),
//.........这里部分代码省略.........
开发者ID:Bootz,项目名称:SkyFire_one,代码行数:101,代码来源:Process.cpp


注:本文中的ACE_Process_Options::working_directory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。