OpenMS
Loading...
Searching...
No Matches
ExternalProcess.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
12
13#include <functional>
14#include <map>
15#include <string>
16#include <vector>
17
18namespace OpenMS
19{
20
32 class OPENMS_DLLAPI ExternalProcess
33 {
34 public:
36 enum class RETURNSTATE
37 {
38 SUCCESS,
39 NONZERO_EXIT,
40 CRASH,
41 FAILED_TO_START
42 };
43
45 enum class IO_MODE
46 {
47 NO_IO,
48 READ_ONLY,
49 WRITE_ONLY,
50 READ_WRITE
51 };
52
55
57 ExternalProcess(std::function<void(const String&)> callbackStdOut, std::function<void(const String&)> callbackStdErr);
58
61
63 void setCallbacks(std::function<void(const String&)> callbackStdOut, std::function<void(const String&)> callbackStdErr);
64
78 RETURNSTATE run(const String& exe, const std::vector<String>& args, const String& working_dir, const bool verbose, String& error_msg,
79 IO_MODE io_mode = IO_MODE::READ_WRITE,
80 const std::map<String, String>& env = {},
81 std::function<void()> idle_callback = nullptr);
82
86 RETURNSTATE run(const String& exe, const std::vector<String>& args, const String& working_dir, const bool verbose,
87 IO_MODE io_mode = IO_MODE::READ_WRITE,
88 const std::map<String, String>& env = {},
89 std::function<void()> idle_callback = nullptr);
90
91 private:
92 std::function<void(const String&)> callbackStdOut_;
93 std::function<void(const String&)> callbackStdErr_;
94 };
95} // ns OpenMS
A wrapper around boost::process to conveniently start an external program and forward its outputs.
Definition ExternalProcess.h:33
std::function< void(const String &)> callbackStdErr_
Definition ExternalProcess.h:93
ExternalProcess()
default Ctor; callbacks for stdout/stderr are empty
RETURNSTATE
result of calling an external executable
Definition ExternalProcess.h:37
void setCallbacks(std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr)
re-wire the callbacks used during run()
IO_MODE
Open mode for the process.
Definition ExternalProcess.h:46
RETURNSTATE run(const String &exe, const std::vector< String > &args, const String &working_dir, const bool verbose, String &error_msg, IO_MODE io_mode=IO_MODE::READ_WRITE, const std::map< String, String > &env={}, std::function< void()> idle_callback=nullptr)
Runs a program and calls the callback functions from time to time if output from the external program...
RETURNSTATE run(const String &exe, const std::vector< String > &args, const String &working_dir, const bool verbose, IO_MODE io_mode=IO_MODE::READ_WRITE, const std::map< String, String > &env={}, std::function< void()> idle_callback=nullptr)
Same as other overload, just without a returned error message.
ExternalProcess(std::function< void(const String &)> callbackStdOut, std::function< void(const String &)> callbackStdErr)
set the callback functions to process stdout and stderr output when the external process generates it
std::function< void(const String &)> callbackStdOut_
Definition ExternalProcess.h:92
A more convenient string class.
Definition String.h:32
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19