cisst-saw
Loading...
Searching...
No Matches
osaPipeExec.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5
6 Author(s): Martin Kelly
7 Created on: 2010-09-23
8
9 (C) Copyright 2010-2019 Johns Hopkins University (JHU), All Rights Reserved.
10
11 --- begin cisst license - do not edit ---
12
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16
17 --- end cisst license ---
18
19*/
20
21#ifndef _osaPipeExec_h
22#define _osaPipeExec_h
23
24#include <vector>
25#include <string>
26
28
29// Always include last
31
34 enum {INTERNALS_SIZE = 64};
35 char Internals[INTERNALS_SIZE];
36
39 static unsigned int SizeOfInternals(void);
40 friend class osaPipeExecTest;
41
42 int ToProgram[2];
43 int FromProgram[2];
44 bool Connected;
45 bool ReadFlag;
46 bool WriteFlag;
47 std::string Name;
48
50 int DoClose(int &n);
51
54 void CloseAllPipes(void);
55
57 void CloseUnusedHandles(void);
58
61 char ** ParseCommand(const std::string & executable,
62 const std::vector<std::string> & arguments);
63
65 void FreeCommand(char **command);
66
67#if (CISST_OS == CISST_WINDOWS)
71 void RestoreIO(int newStdin, int newStdout);
72#endif
73
74 public:
76 osaPipeExec(const std::string & name = "unnamed");
77
80
86 bool Open(const std::string & executable, const std::string & mode,
87 bool noWindow = false);
88
95
96 bool Open(const std::string & executable,
97 const std::vector<std::string> & parameters,
98 const std::string & mode, bool noWindow = false);
99
106 bool Close(bool killProcess = true);
107
110 int Read(char * buffer, int maxLength) const;
111
115 std::string Read(int maxLength) const;
116
120 int ReadUntil(char * buffer, int maxLength, char stopChar, double timeoutSec = 0.0) const;
121
124 std::string ReadUntil(int maxLength, char stopChar, double timeoutSec = 0.0) const;
125
127 std::string ReadString(int maxLength, double timeoutSec = 0.0) const;
128
131 int Write(const char * buffer);
132
135 int Write(const char * buffer, int n);
136
139 int Write(const std::string & s);
140
143 int Write(const std::string & s, int n);
144
147 bool IsConnected(void) const;
148
150 bool IsProcessRunning(void) const;
151
153 const std::string & GetName(void) const;
154};
155
156#endif // _osaPipeExec_h
int Write(const char *buffer, int n)
int Write(const std::string &s, int n)
std::string Read(int maxLength) const
int Read(char *buffer, int maxLength) const
bool IsConnected(void) const
osaPipeExec(const std::string &name="unnamed")
int Write(const std::string &s)
bool IsProcessRunning(void) const
bool Open(const std::string &executable, const std::string &mode, bool noWindow=false)
int ReadUntil(char *buffer, int maxLength, char stopChar, double timeoutSec=0.0) const
std::string ReadString(int maxLength, double timeoutSec=0.0) const
int Write(const char *buffer)
~osaPipeExec(void)
const std::string & GetName(void) const
friend class osaPipeExecTest
Definition osaPipeExec.h:40
bool Open(const std::string &executable, const std::vector< std::string > &parameters, const std::string &mode, bool noWindow=false)
std::string ReadUntil(int maxLength, char stopChar, double timeoutSec=0.0) const
bool Close(bool killProcess=true)
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Portability across compilers and operating systems tools.
Macros to export the symbols of cisstOSAbstraction (in a Dll).