什么是C ++中Java对应的ProcessBuilder?

时间:2019-08-08 11:11:59

标签: java c++ command pipe processbuilder

有一个python程序未安装在系统的默认路径中。如何用C ++调用类似于Java中ProcessBuilder功能的程序。

与C ++中的以下内容等效

application.properties

1 个答案:

答案 0 :(得分:1)

https://en.cppreference.com/w/cpp/utility/program/system

int wstatus = std::system("python3 software param");

返回值是实现定义的值。在Posix系统上,它包含许多可以使用以下宏提取的信息:

WIFEXITED(wstatus)
          returns true if the child terminated normally, that is,  by  calling  exit(3)  or
          _exit(2), or by returning from main().

WEXITSTATUS(wstatus)
          returns  the  exit status of the child.  This consists of the least significant 8
          bits of the status argument that the child specified in  a  call  to  exit(3)  or
          _exit(2)  or as the argument for a return statement in main().  This macro should
          be employed only if WIFEXITED returned true.

WIFSIGNALED(wstatus)
          returns true if the child process was terminated by a signal.

WTERMSIG(wstatus)
          returns the number of the signal that caused  the  child  process  to  terminate.
          This macro should be employed only if WIFSIGNALED returned true.

WCOREDUMP(wstatus)
          returns  true  if  the child produced a core dump.  This macro should be employed
          only if WIFSIGNALED returned true.

          This macro is not specified in POSIX.1-2001 and is not  available  on  some  UNIX
          implementations  (e.g.,  AIX,  SunOS).   Therefore, enclose its use inside #ifdef
          WCOREDUMP ... #endif.

WIFSTOPPED(wstatus)
          returns true if the child process was stopped by delivery of a  signal;  this  is
          possible  only  if  the  call was done using WUNTRACED or when the child is being
          traced (see ptrace(2)).

WSTOPSIG(wstatus)
          returns the number of the signal which caused the  child  to  stop.   This  macro
          should be employed only if WIFSTOPPED returned true.

WIFCONTINUED(wstatus)
          (since Linux 2.6.10) returns true if the child process was resumed by delivery of
          SIGCONT.