GNU Octave  9.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-2024 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  OCTAVE_DEFAULT_COPY_MOVE_DELETE (process_execution_result)
52 
53  static OCTINTERP_API process_execution_result
54  of_success (int exit_status, const std::string& stdout_output);
55 
56  static OCTINTERP_API process_execution_result
57  of_error (int status, const std::string& err_msg);
58 
59  int status () const { return m_status; }
60 
61  int exit_status () const { return m_exit_status; }
62 
63  std::string err_msg () const { return m_err_msg; }
64 
65  std::string stdout_output () const { return m_stdout_output; }
66 
67 private:
68 
69  // Launch status of the process, 0 for success, nonzero for error.
70  int m_status;
71 
72  // Error message if executing command failed.
73  std::string m_err_msg;
74 
75  // Exit status of the process.
76  int m_exit_status;
77 
78  // Collected stdout output of the process.
79  std::string m_stdout_output;
80 };
81 
82 extern OCTINTERP_API process_execution_result
83 run_command_and_return_output (const std::string& cmd_str);
84 
85 OCTAVE_END_NAMESPACE(octave)
86 
87 #endif
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 stdout_output() const
Definition: oct-process.h:65
std::string err_msg() const
Definition: oct-process.h:63
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
process_execution_result run_command_and_return_output(const std::string &cmd_str)
Definition: oct-process.cc:51