GNU Octave  8.1.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-2023 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 
34 
35 class
37 {
38 public:
39 
41  : m_status (-1), m_err_msg (), m_exit_status (-1), m_stdout_output ()
42  { }
43 
44  process_execution_result (int status, int exit_status,
45  const std::string& stdout_output,
46  const std::string& err_msg)
47  : m_status (status), m_err_msg (err_msg), m_exit_status (exit_status),
48  m_stdout_output (stdout_output)
49  { }
50 
51  static OCTINTERP_API process_execution_result
52  of_success (int exit_status, const std::string& stdout_output);
53 
54  static OCTINTERP_API process_execution_result
55  of_error (int status, const std::string& err_msg);
56 
57  int status (void) const { return m_status; }
58 
59  int exit_status (void) const { return m_exit_status; }
60 
61  std::string err_msg (void) const { return m_err_msg; }
62 
63  std::string stdout_output (void) const { return m_stdout_output; }
64 
65 private:
66 
67  // Launch status of the process, 0 for success, nonzero for error.
68  int m_status;
69 
70  // Error message if executing command failed.
71  std::string m_err_msg;
72 
73  // Exit status of the process.
75 
76  // Collected stdout output of the process.
77  std::string m_stdout_output;
78 };
79 
80 extern OCTINTERP_API process_execution_result
81 run_command_and_return_output (const std::string& cmd_str);
82 
84 
85 #endif
OCTAVE_END_NAMESPACE(octave)
int status(void) const
Definition: oct-process.h:57
int exit_status(void) const
Definition: oct-process.h:59
std::string stdout_output(void) const
Definition: oct-process.h:63
process_execution_result(int status, int exit_status, const std::string &stdout_output, const std::string &err_msg)
Definition: oct-process.h:44
std::string err_msg(void) const
Definition: oct-process.h:61
std::string m_stdout_output
Definition: oct-process.h:77
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API process_execution_result run_command_and_return_output(const std::string &cmd_str)
Definition: oct-process.cc:51