The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. //==============================================================================
  20. /**
  21. Launches and monitors a child process.
  22. This class lets you launch an executable, and read its output. You can also
  23. use it to check whether the child process has finished.
  24. @tags{Core}
  25. */
  26. class JUCE_API ChildProcess
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a process object.
  31. To actually launch the process, use start().
  32. */
  33. ChildProcess();
  34. /** Destructor.
  35. Note that deleting this object won't terminate the child process.
  36. */
  37. ~ChildProcess();
  38. /** These flags are used by the start() methods. */
  39. enum StreamFlags
  40. {
  41. wantStdOut = 1,
  42. wantStdErr = 2
  43. };
  44. /** Attempts to launch a child process command.
  45. The command should be the name of the executable file, followed by any arguments
  46. that are required.
  47. If the process has already been launched, this will launch it again. If a problem
  48. occurs, the method will return false.
  49. The streamFlags is a combinations of values to indicate which of the child's output
  50. streams should be read and returned by readProcessOutput().
  51. */
  52. bool start (const String& command, int streamFlags = wantStdOut | wantStdErr);
  53. /** Attempts to launch a child process command.
  54. The first argument should be the name of the executable file, followed by any other
  55. arguments that are needed.
  56. If the process has already been launched, this will launch it again. If a problem
  57. occurs, the method will return false.
  58. The streamFlags is a combinations of values to indicate which of the child's output
  59. streams should be read and returned by readProcessOutput().
  60. */
  61. bool start (const StringArray& arguments, int streamFlags = wantStdOut | wantStdErr);
  62. /** Returns true if the child process is alive. */
  63. bool isRunning() const;
  64. /** Attempts to read some output from the child process.
  65. This will attempt to read up to the given number of bytes of data from the
  66. process. It returns the number of bytes that were actually read.
  67. */
  68. int readProcessOutput (void* destBuffer, int numBytesToRead);
  69. /** Blocks until the process has finished, and then returns its complete output
  70. as a string.
  71. */
  72. String readAllProcessOutput();
  73. /** Blocks until the process is no longer running. */
  74. bool waitForProcessToFinish (int timeoutMs) const;
  75. /** If the process has finished, this returns its exit code. */
  76. uint32 getExitCode() const;
  77. /** Attempts to kill the child process.
  78. Returns true if it succeeded. Trying to read from the process after calling this may
  79. result in undefined behaviour.
  80. */
  81. bool kill();
  82. private:
  83. //==============================================================================
  84. class ActiveProcess;
  85. std::unique_ptr<ActiveProcess> activeProcess;
  86. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcess)
  87. };
  88. } // namespace juce