mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
processInterface.hpp
Go to the documentation of this file.
1/** \file processInterface.hpp
2 * \author Jared R. Males (jaredmales@gmail.com)
3 * \brief Process interface facilities
4 * \ingroup IPC
5 *
6 */
7
8//***********************************************************************//
9// Copyright 2015, 2016, 2017, 2018 Jared R. Males (jaredmales@gmail.com)
10//
11// This file is part of mxlib.
12//
13// mxlib is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// mxlib is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25//***********************************************************************//
26
27#ifndef ipc_processInterface_hpp
28#define ipc_processInterface_hpp
29
30#include <vector>
31#include <string>
32
33#include "../mxlib.hpp"
34#include "ipc.hpp"
35
36namespace mx
37{
38namespace ipc
39{
40
41/// Run a process and copy the output to a string
42/** Uses popen, so the attendant precautions about privileges apply.
43 *
44 * \param cmd is the command to run
45 * \param resp is the string to copy the response to.
46 * \param respsz is the available size of the string.
47 *
48 * \retval 0 on success
49 * \retval -1 on error
50 *
51 * \ingroup IPC
52 */
53int command_response( const char *cmd, char *resp, size_t respsz );
54
55/// Runs a command (with parameters) passed in using fork/exec
56/** A new process is fork()-ed, and the child runs execvp with command provided. The output of the process
57 * is captured in \p commandOutput, and error messages in \p commandStderr.
58 *
59 * The process return value in \p retVal is only meaningful if this function returns 0.
60 *
61 * If this function returns -1, the last entry in \p commandStderr will contain a message,
62 * and errno may be useful.
63 *
64 * \returns 0 on success
65 * \returns -1 on error
66 *
67 * \ingroup IPC
68 */
69int runCommand(
70 int &retVal, ///< [out] the return value of the process. Only meaningful if this returns 0.
71 std::vector<std::string>
72 &commandOutput, ///< [out] the output, line by line. If an error, first entry contains the message.
73 std::vector<std::string> &commandStderr, ///< [out] the output of stderr.
74 const std::vector<std::string> &commandList ///< [in] command to be run, with one entry per command line word
75);
76
77} // namespace ipc
78} // namespace mx
79
80#endif // ipc_processInterface_hpp
int command_response(const char *cmd, char *resp, size_t respsz)
Run a process and copy the output to a string.
int runCommand(int &retVal, std::vector< std::string > &commandOutput, std::vector< std::string > &commandStderr, const std::vector< std::string > &commandList)
Runs a command (with parameters) passed in using fork/exec.
Declarations for the mxlib interprocess communication (IPC) tools.
The mxlib c++ namespace.
Definition mxError.hpp:106