VTK  9.3.0
vtkExecutableRunner.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 #ifndef vtkExecutableRunner_h
4 #define vtkExecutableRunner_h
5 
6 #include "vtkCommonSystemModule.h" // For export macro
7 #include "vtkObject.h"
8 
9 #include "vtksys/Process.h" // For class vtksysProcess
10 
11 #include <string> // for class std::string
12 #include <vector> // for class std::vector
13 
28 VTK_ABI_NAMESPACE_BEGIN
29 class VTKCOMMONSYSTEM_EXPORT vtkExecutableRunner : public vtkObject
30 {
31 public:
34  void PrintSelf(ostream& os, vtkIndent indent) override;
35 
36  vtkExecutableRunner() = default;
37  ~vtkExecutableRunner() override = default;
38 
43  void Execute();
44 
46 
52  vtkSetMacro(Timeout, double);
53  vtkGetMacro(Timeout, double);
55 
57 
62  vtkSetMacro(RightTrimResult, bool);
63  vtkGetMacro(RightTrimResult, bool);
64  vtkBooleanMacro(RightTrimResult, bool);
66 
68 
74 
76 
83  vtkSetMacro(ExecuteInSystemShell, bool);
84  vtkGetMacro(ExecuteInSystemShell, bool);
85  vtkBooleanMacro(ExecuteInSystemShell, bool);
87 
89 
95  virtual void AddArgument(const std::string& arg);
96  virtual void ClearArguments();
99 
101 
107 
113  vtkGetMacro(ReturnValue, int);
114 
115 protected:
116  vtkSetMacro(StdOut, std::string);
117  vtkSetMacro(StdErr, std::string);
118 
119  std::vector<std::string> GetCommandToExecute() const;
120  int ExitProcess(vtksysProcess* process);
121 
122 private:
123  vtkExecutableRunner(const vtkExecutableRunner&) = delete;
124  void operator=(const vtkExecutableRunner&) = delete;
125 
126  bool RightTrimResult = true;
127  double Timeout = 5;
128  std::string Command;
129  int ReturnValue = -1;
130  bool ExecuteInSystemShell = true;
131  std::vector<std::string> Arguments;
132 
133  std::string StdOut;
134  std::string StdErr;
135 };
136 
137 VTK_ABI_NAMESPACE_END
138 #endif // vtkExecutableRunner_h
Launch a process on the current machine and get its output.
int ExitProcess(vtksysProcess *process)
void Execute()
Execute the command currently set if any.
virtual void AddArgument(const std::string &arg)
API to control arguments passed to the command when ExecuteInSystemShell is false.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkGetCharFromStdStringMacro(StdOut)
Get output of the previously run command.
~vtkExecutableRunner() override=default
vtkGetCharFromStdStringMacro(Command)
Set/Get command to execute.
vtkExecutableRunner()=default
vtkSetStdStringFromCharMacro(Command)
Set/Get command to execute.
static vtkExecutableRunner * New()
vtkGetCharFromStdStringMacro(StdErr)
Get output of the previously run command.
std::vector< std::string > GetCommandToExecute() const
virtual void ClearArguments()
API to control arguments passed to the command when ExecuteInSystemShell is false.
virtual vtkIdType GetNumberOfArguments() const
API to control arguments passed to the command when ExecuteInSystemShell is false.
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
@ string
Definition: vtkX3D.h:490
int vtkIdType
Definition: vtkType.h:315