Beamlib 3.3.2
This is the Beam C++ class library.
Loading...
Searching...
No Matches
BProc.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BProc.h BProc class
3 * T.Barnaby, Beam Ltd, 2015-01-01
4 * Copyright (c) 2015 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5 * For license see LICENSE.txt at the root of the beamlib source tree.
6 *******************************************************************************
7 *
8 */
32#ifndef BProc_h
33#define BProc_h
34
35#include <BError.h>
36#include <signal.h>
37
39class BProc {
40public:
41 BProc();
42 ~BProc();
43
44 BError usePipes(Bool fileIn, Bool fileOut, Bool fileErr);
45 BError runForeground(BString cmd, BStringList argList = BStringList(), int* status = 0, int timeoutMs = -1);
47
48 int getPid();
49 int getFd(int cmdFd);
50 BError wait(int& status, int timeoutMs = -1);
51 BError kill(int sig = SIGTERM);
52 void finish();
53
54private:
55 BError run(BString cmd, BStringList argList, Bool background, int* status, int timeoutMs);
56 BError pipesOpen();
57 void pipesCleanup();
58
59 int opid;
60 Bool oioFiles[3];
61 int opipeIn[2];
62 int opipeOut[2];
63 int opipeErr[2];
64 int ochildErrno;
65};
66#endif
BList< BString > BStringList
Definition: BString.h:209
bool Bool
Definition: BTypes.h:18
BUInt8 cmd
Definition: BoapMc.h:3
Error return class. This class is used to return the error status from a function....
Definition: BError.h:31
Implements system process manager.
Definition: BProc.h:39
BError wait(int &status, int timeoutMs=-1)
Wait for the process to complete. The programs exist status is returned in status....
Definition: BProc.cpp:69
BError runBackground(BString cmd, BStringList argList=BStringList())
Run the program in the background.
Definition: BProc.cpp:52
BProc()
Definition: BProc.cpp:18
BError runForeground(BString cmd, BStringList argList=BStringList(), int *status=0, int timeoutMs=-1)
Run the program in the foreground with optional status return value and timeout.
Definition: BProc.cpp:48
int getFd(int cmdFd)
Return the stdin - 0, stdout - 1 or stderr -2 file descriptor pipes to send or receive data to/from t...
Definition: BProc.cpp:60
int getPid()
Return the process ID of the program.
Definition: BProc.cpp:56
BError kill(int sig=SIGTERM)
Kill the process by sending it a signal.
Definition: BProc.cpp:108
void finish()
Tidy up when finised (closes all pipes).
Definition: BProc.cpp:119
BError usePipes(Bool fileIn, Bool fileOut, Bool fileErr)
Enable IO pipes for the processes standard file descriptors.
Definition: BProc.cpp:36
~BProc()
Definition: BProc.cpp:32
This class stores and manipulates ASCII strings.
Definition: BString.h:20