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.

94 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_CHILDPROCESS_JUCEHEADER__
  19. #define __JUCE_CHILDPROCESS_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Launches and monitors a child process.
  23. This class lets you launch an executable, and read its output. You can also
  24. use it to check whether the child process has finished.
  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. /** Attempts to launch a child process command.
  39. The command should be the name of the executable file, followed by any arguments
  40. that are required.
  41. If the process has already been launched, this will launch it again. If a problem
  42. occurs, the method will return false.
  43. */
  44. bool start (const String& command);
  45. /** Returns true if the child process is alive. */
  46. bool isRunning() const;
  47. /** Attempts to read some output from the child process.
  48. This will attempt to read up to the given number of bytes of data from the
  49. process. It returns the number of bytes that were actually read.
  50. */
  51. int readProcessOutput (void* destBuffer, int numBytesToRead);
  52. /** Blocks until the process has finished, and then returns its complete output
  53. as a string.
  54. */
  55. String readAllProcessOutput();
  56. /** Blocks until the process is no longer running. */
  57. bool waitForProcessToFinish (int timeoutMs) const;
  58. /** Attempts to kill the child process.
  59. Returns true if it succeeded. Trying to read from the process after calling this may
  60. result in undefined behaviour.
  61. */
  62. bool kill();
  63. private:
  64. //==============================================================================
  65. class ActiveProcess;
  66. friend class ScopedPointer<ActiveProcess>;
  67. ScopedPointer<ActiveProcess> activeProcess;
  68. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcess);
  69. };
  70. #endif // __JUCE_CHILDPROCESS_JUCEHEADER__