E-MailRelay
gexecutablecommand.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2023 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gexecutablecommand.h
19///
20
21#ifndef G_EXECUTABLE_COMMAND_H
22#define G_EXECUTABLE_COMMAND_H
23
24#include "gdef.h"
25#include "gpath.h"
26#include "gstringarray.h"
27#include "gexception.h"
28#include "gstringarray.h"
29#include <string>
30
31namespace G
32{
33 class ExecutableCommand ;
34}
35
36//| \class G::ExecutableCommand
37/// A structure representing an external program, holding a path
38/// and a set of arguments. The constructor takes a complete command-line and splits it up
39/// into the executable part and a list of command-line parameters. If the
40/// command-line starts with a script then the contructed command-line may
41/// be for the appropriate interpreter (depending on the o/s).
42///
43/// \see G::Path, G::Args
44///
46{
47public:
48 G_EXCEPTION( WindowsError , tx("cannot determine the windows directory") ) ;
49
50 explicit ExecutableCommand( const std::string & command_line = {} ) ;
51 ///< Constructor taking a complete command-line. The
52 ///< command-line is split up on unescaped-and-unquoted
53 ///< space characters. Uses G::Arg::parse() in its
54 ///< implementation.
55
56 ExecutableCommand( const G::Path & exe , const StringArray & args ) ;
57 ///< Constructor taking the executable and arguments
58 ///< explicitly.
59
60 Path exe() const ;
61 ///< Returns the executable.
62
63 StringArray args() const ;
64 ///< Returns the command-line arguments.
65
66 void add( const std::string & arg ) ;
67 ///< Adds a command-line argument.
68
69 void insert( const G::StringArray & ) ;
70 ///< Inserts at the front of the command-line.
71 ///< The first element becomes the new executable.
72
73 std::string displayString() const ;
74 ///< Returns a printable representation for logging and diagnostics.
75
76private:
77 G::Path m_exe ;
78 G::StringArray m_args ;
79} ;
80
81#endif
A structure representing an external program, holding a path and a set of arguments.
ExecutableCommand(const std::string &command_line={})
Constructor taking a complete command-line.
void add(const std::string &arg)
Adds a command-line argument.
StringArray args() const
Returns the command-line arguments.
std::string displayString() const
Returns a printable representation for logging and diagnostics.
void insert(const G::StringArray &)
Inserts at the front of the command-line.
Path exe() const
Returns the executable.
A Path object represents a file system path.
Definition: gpath.h:73
Low-level classes.
Definition: garg.h:30
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().
Definition: ggettext.h:84