GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-process.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2019-2025 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
36{
37public:
38
40 : m_status (-1), m_err_msg (), m_exit_status (-1), m_stdout_output ()
41 { }
42
43 process_execution_result (int status, int exit_status,
44 const std::string& stdout_output,
45 const std::string& err_msg)
46 : m_status (status), m_err_msg (err_msg), m_exit_status (exit_status),
47 m_stdout_output (stdout_output)
48 { }
49
50 OCTAVE_DEFAULT_COPY_MOVE_DELETE (process_execution_result)
51
52 static OCTINTERP_API process_execution_result
53 of_success (int exit_status, const std::string& stdout_output);
54
55 static OCTINTERP_API process_execution_result
56 of_error (int status, const std::string& err_msg);
57
58 int status () const { return m_status; }
59
60 int exit_status () const { return m_exit_status; }
61
62 std::string err_msg () const { return m_err_msg; }
63
64 std::string stdout_output () const { return m_stdout_output; }
65
66private:
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.
75 int m_exit_status;
76
77 // Collected stdout output of the process.
78 std::string m_stdout_output;
79};
80
81extern OCTINTERP_API process_execution_result
82run_command_and_return_output (const std::string& cmd_str);
83
84OCTAVE_END_NAMESPACE(octave)
85
86#endif
process_execution_result(int status, int exit_status, const std::string &stdout_output, const std::string &err_msg)
Definition oct-process.h:43
std::string stdout_output() const
Definition oct-process.h:64
std::string err_msg() const
Definition oct-process.h:62
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
process_execution_result run_command_and_return_output(const std::string &cmd_str)