ObjFW
OFSubprocess.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __STDC_LIMIT_MACROS
21 # define __STDC_LIMIT_MACROS
22 #endif
23 #ifndef __STDC_CONSTANT_MACROS
24 # define __STDC_CONSTANT_MACROS
25 #endif
26 
27 #include "objfw-defs.h"
28 
29 #ifdef OF_HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32 
33 #import "OFStream.h"
34 #import "OFKernelEventObserver.h"
35 #import "OFString.h"
36 
37 #ifdef OF_WINDOWS
38 # include <windows.h>
39 #endif
40 
41 OF_ASSUME_NONNULL_BEGIN
42 
43 @class OFArray OF_GENERIC(ObjectType);
44 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
45 
51 OF_SUBCLASSING_RESTRICTED
53 #ifndef OF_WINDOWS
55 #endif
56 {
57 #ifndef OF_WINDOWS
58  pid_t _pid;
59  int _readPipe[2], _writePipe[2];
60 #else
61  HANDLE _handle, _readPipe[2], _writePipe[2];
62 #endif
63  int _status;
64  bool _atEndOfStream;
65 }
66 
75 + (instancetype)subprocessWithProgram: (OFString *)program;
76 
86 + (instancetype)
87  subprocessWithProgram: (OFString *)program
88  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
89 
101 + (instancetype)
102  subprocessWithProgram: (OFString *)program
103  programName: (OFString *)programName
104  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
105 
122 + (instancetype)
123  subprocessWithProgram: (OFString *)program
124  programName: (OFString *)programName
125  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments
126  environment: (nullable OFDictionary
127  OF_GENERIC(OFString *, OFString *) *)environment;
128 
129 - (instancetype)init OF_UNAVAILABLE;
130 
139 - (instancetype)initWithProgram: (OFString *)program;
140 
150 - (instancetype)
151  initWithProgram: (OFString *)program
152  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
153 
165 - (instancetype)
166  initWithProgram: (OFString *)program
167  programName: (OFString *)programName
168  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
169 
187 - (instancetype)
188  initWithProgram: (OFString *)program
189  programName: (OFString *)programName
190  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments
191  environment: (nullable OFDictionary
192  OF_GENERIC(OFString *, OFString *) *)environment
193  OF_DESIGNATED_INITIALIZER;
194 
204 - (void)closeForWriting;
205 
215 - (int)waitForTermination;
216 @end
217 
218 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:107
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
A base class for different types of streams.
Definition: OFStream.h:278
A class for handling strings.
Definition: OFString.h:142
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:82
A class for stream-like communication with a newly created subprocess.
Definition: OFSubprocess.h:52
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...