ObjFW
OFProcess.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #include "objfw-defs.h"
25 
26 #ifdef OF_HAVE_SYS_TYPES_H
27 # include <sys/types.h>
28 #endif
29 
30 #import "OFStream.h"
31 #import "OFString.h"
32 
33 #ifdef OF_WINDOWS
34 # include <windows.h>
35 #endif
36 
37 OF_ASSUME_NONNULL_BEGIN
38 
39 @class OFArray OF_GENERIC(ObjectType);
40 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
41 
47 @interface OFProcess: OFStream
48 {
49 #ifndef OF_WINDOWS
50  pid_t _pid;
51  int _readPipe[2], _writePipe[2];
52 #else
53  HANDLE _process, _readPipe[2], _writePipe[2];
54 #endif
55  int _status;
56  bool _atEndOfStream;
57 }
58 
67 + (instancetype)processWithProgram: (OFString *)program;
68 
78 + (instancetype)
79  processWithProgram: (OFString *)program
80  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
81 
93 + (instancetype)
94  processWithProgram: (OFString *)program
95  programName: (OFString *)programName
96  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
97 
114 + (instancetype)
115  processWithProgram: (OFString *)program
116  programName: (OFString *)programName
117  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments
118  environment: (nullable OFDictionary
119  OF_GENERIC(OFString *, OFString *) *)environment;
120 
121 - init OF_UNAVAILABLE;
122 
131 - initWithProgram: (OFString *)program;
132 
142 - initWithProgram: (OFString *)program
143  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
144 
156 - initWithProgram: (OFString *)program
157  programName: (OFString *)programName
158  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments;
159 
176 - initWithProgram: (OFString *)program
177  programName: (OFString *)programName
178  arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments
179  environment: (nullable OFDictionary
180  OF_GENERIC(OFString *, OFString *) *)environment
181  OF_DESIGNATED_INITIALIZER;
182 
190 - (void)closeForWriting;
191 @end
192 
193 OF_ASSUME_NONNULL_END
A class for handling strings.
Definition: OFString.h:114
A class for stream-like communication with a newly created process.
Definition: OFProcess.h:47
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:54
An abstract class for storing objects in an array.
Definition: OFArray.h:89
void closeForWriting()
Closes the write direction of the process.
Definition: OFProcess.m:552
A base class for different types of streams.
Definition: OFStream.h:88