GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-process.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2019-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (oct_process_h)
27 #define oct_process_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 namespace octave
34 {
35  OCTINTERP_API
36  class
38  {
39  public:
40 
42  : m_status (-1), m_err_msg (), m_exit_status (-1), m_stdout_output ()
43  { }
44 
45  process_execution_result (int status, int exit_status,
46  const std::string& stdout_output,
47  const std::string& err_msg)
48  : m_status (status), m_err_msg (err_msg), m_exit_status (exit_status),
49  m_stdout_output (stdout_output)
50  { }
51 
53  of_success (int exit_status, const std::string& stdout_output);
54 
56  of_error (int status, const std::string& err_msg);
57 
58  int status (void) const { return m_status; }
59 
60  int exit_status (void) const { return m_exit_status; }
61 
62  std::string err_msg (void) const { return m_err_msg; }
63 
64  std::string stdout_output (void) const { return m_stdout_output; }
65 
66  private:
67 
68  // Launch status of the process, 0 for success, nonzero for error.
69  int m_status;
70 
71  // Error message if executing command failed.
72  std::string m_err_msg;
73 
74  // Exit status of the process.
76 
77  // Collected stdout output of the process.
78  std::string m_stdout_output;
79  };
80 
81  extern OCTINTERP_API process_execution_result
82  run_command_and_return_output (const std::string& cmd_str);
83 }
84 
85 #endif
std::string err_msg(void) const
Definition: oct-process.h:62
process_execution_result(int status, int exit_status, const std::string &stdout_output, const std::string &err_msg)
Definition: oct-process.h:45
std::string stdout_output(void) const
Definition: oct-process.h:64
OCTINTERP_API process_execution_result run_command_and_return_output(const std::string &cmd_str)
Definition: oct-process.cc:54