GDAL
cpl_spawn.h
1/**********************************************************************
2 *
3 * Project: CPL - Common Portability Library
4 * Purpose: Implement CPLSystem().
5 * Author: Even Rouault, <even dot rouault at spatialys.com>
6 *
7 **********************************************************************
8 * Copyright (c) 2013, Even Rouault <even dot rouault at spatialys.com>
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13#ifndef CPL_SPAWN_H_INCLUDED
14#define CPL_SPAWN_H_INCLUDED
15
16#include "cpl_vsi.h"
17
19
20/* -------------------------------------------------------------------- */
21/* Spawn a process. */
22/* -------------------------------------------------------------------- */
23
24int CPL_DLL CPLSpawn(const char *const papszArgv[], VSILFILE *fin,
25 VSILFILE *fout, int bDisplayErr);
26
27#ifdef _WIN32
28#include <windows.h>
29typedef HANDLE CPL_FILE_HANDLE;
30#define CPL_FILE_INVALID_HANDLE CPL_NULLPTR
31typedef DWORD CPL_PID;
32#else
33#include <sys/types.h>
34typedef int CPL_FILE_HANDLE;
35#define CPL_FILE_INVALID_HANDLE -1
36typedef pid_t CPL_PID;
37#endif
38
39typedef struct _CPLSpawnedProcess CPLSpawnedProcess;
40
41CPLSpawnedProcess CPL_DLL *
42CPLSpawnAsync(int (*pfnMain)(CPL_FILE_HANDLE, CPL_FILE_HANDLE),
43 const char *const papszArgv[], int bCreateInputPipe,
44 int bCreateOutputPipe, int bCreateErrorPipe, char **papszOptions);
45CPL_PID CPL_DLL CPLSpawnAsyncGetChildProcessId(CPLSpawnedProcess *p);
46int CPL_DLL CPLSpawnAsyncFinish(CPLSpawnedProcess *p, int bWait, int bKill);
47CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetInputFileHandle(CPLSpawnedProcess *p);
48CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetOutputFileHandle(CPLSpawnedProcess *p);
49CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetErrorFileHandle(CPLSpawnedProcess *p);
50void CPL_DLL CPLSpawnAsyncCloseInputFileHandle(CPLSpawnedProcess *p);
51void CPL_DLL CPLSpawnAsyncCloseOutputFileHandle(CPLSpawnedProcess *p);
52void CPL_DLL CPLSpawnAsyncCloseErrorFileHandle(CPLSpawnedProcess *p);
53
54int CPL_DLL CPLPipeRead(CPL_FILE_HANDLE fin, void *data, int length);
55int CPL_DLL CPLPipeWrite(CPL_FILE_HANDLE fout, const void *data, int length);
56
58
59#endif // CPL_SPAWN_H_INCLUDED
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
Standard C Covers.
struct VSIVirtualHandle VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition cpl_vsi.h:141