cpl_spawn.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**********************************************************************
  2. * $Id: cpl_spawn.h 27044 2014-03-16 23:41:27Z rouault $
  3. *
  4. * Project: CPL - Common Portability Library
  5. * Purpose: Implement CPLSystem().
  6. * Author: Even Rouault, <even dot rouault at mines dash paris dot org>
  7. *
  8. **********************************************************************
  9. * Copyright (c) 2013, Even Rouault <even dot rouault at mines-paris dot org>
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included
  19. * in all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  24. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. * DEALINGS IN THE SOFTWARE.
  28. ****************************************************************************/
  29. #ifndef CPL_SPAWN_H_INCLUDED
  30. #define CPL_SPAWN_H_INCLUDED
  31. #include "cpl_vsi.h"
  32. CPL_C_START
  33. /* -------------------------------------------------------------------- */
  34. /* Spawn a process. */
  35. /* -------------------------------------------------------------------- */
  36. int CPL_DLL CPLSpawn( const char * const papszArgv[], VSILFILE* fin, VSILFILE* fout,
  37. int bDisplayErr );
  38. #ifdef WIN32
  39. #include <windows.h>
  40. typedef HANDLE CPL_FILE_HANDLE;
  41. #define CPL_FILE_INVALID_HANDLE NULL
  42. typedef DWORD CPL_PID;
  43. #else
  44. #include <sys/types.h>
  45. typedef int CPL_FILE_HANDLE;
  46. #define CPL_FILE_INVALID_HANDLE -1
  47. typedef pid_t CPL_PID;
  48. #endif
  49. typedef struct _CPLSpawnedProcess CPLSpawnedProcess;
  50. CPLSpawnedProcess CPL_DLL* CPLSpawnAsync( int (*pfnMain)(CPL_FILE_HANDLE, CPL_FILE_HANDLE),
  51. const char * const papszArgv[],
  52. int bCreateInputPipe,
  53. int bCreateOutputPipe,
  54. int bCreateErrorPipe,
  55. char** papszOptions );
  56. CPL_PID CPL_DLL CPLSpawnAsyncGetChildProcessId(CPLSpawnedProcess* p);
  57. int CPL_DLL CPLSpawnAsyncFinish(CPLSpawnedProcess* p, int bWait, int bKill);
  58. CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetInputFileHandle(CPLSpawnedProcess* p);
  59. CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetOutputFileHandle(CPLSpawnedProcess* p);
  60. CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetErrorFileHandle(CPLSpawnedProcess* p);
  61. void CPL_DLL CPLSpawnAsyncCloseInputFileHandle(CPLSpawnedProcess* p);
  62. void CPL_DLL CPLSpawnAsyncCloseOutputFileHandle(CPLSpawnedProcess* p);
  63. void CPL_DLL CPLSpawnAsyncCloseErrorFileHandle(CPLSpawnedProcess* p);
  64. int CPL_DLL CPLPipeRead(CPL_FILE_HANDLE fin, void* data, int length);
  65. int CPL_DLL CPLPipeWrite(CPL_FILE_HANDLE fout, const void* data, int length);
  66. CPL_C_END
  67. #endif // CPL_SPAWN_H_INCLUDED