VTK  9.3.1
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:
32  static vtkExecutableRunner* New();
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 
71  vtkGetCharFromStdStringMacro(Command);
72  vtkSetStdStringFromCharMacro(Command);
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();
97  virtual vtkIdType GetNumberOfArguments() const;
99 
101 
104  vtkGetCharFromStdStringMacro(StdOut);
105  vtkGetCharFromStdStringMacro(StdErr);
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
abstract base class for most VTK objects
Definition: vtkObject.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int vtkIdType
Definition: vtkType.h:315
Launch a process on the current machine and get its output.
a simple class to control print indentation
Definition: vtkIndent.h:28
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...