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.

106 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_CHILDPROCESS_H_INCLUDED
  22. #define JUCE_CHILDPROCESS_H_INCLUDED
  23. //==============================================================================
  24. /**
  25. Launches and monitors a child process.
  26. This class lets you launch an executable, and read its output. You can also
  27. use it to check whether the child process has finished.
  28. */
  29. class JUCE_API ChildProcess
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates a process object.
  34. To actually launch the process, use start().
  35. */
  36. ChildProcess();
  37. /** Destructor.
  38. Note that deleting this object won't terminate the child process.
  39. */
  40. ~ChildProcess();
  41. /** Attempts to launch a child process command.
  42. The command should be the name of the executable file, followed by any arguments
  43. that are required.
  44. If the process has already been launched, this will launch it again. If a problem
  45. occurs, the method will return false.
  46. */
  47. bool start (const String& command);
  48. /** Attempts to launch a child process command.
  49. The first argument should be the name of the executable file, followed by any other
  50. arguments that are needed.
  51. If the process has already been launched, this will launch it again. If a problem
  52. occurs, the method will return false.
  53. */
  54. bool start (const StringArray& arguments);
  55. /** Returns true if the child process is alive. */
  56. bool isRunning() const;
  57. /** Attempts to read some output from the child process.
  58. This will attempt to read up to the given number of bytes of data from the
  59. process. It returns the number of bytes that were actually read.
  60. */
  61. int readProcessOutput (void* destBuffer, int numBytesToRead);
  62. /** Blocks until the process has finished, and then returns its complete output
  63. as a string.
  64. */
  65. String readAllProcessOutput();
  66. /** Blocks until the process is no longer running. */
  67. bool waitForProcessToFinish (int timeoutMs) const;
  68. /** Attempts to kill the child process.
  69. Returns true if it succeeded. Trying to read from the process after calling this may
  70. result in undefined behaviour.
  71. */
  72. bool kill();
  73. private:
  74. //==============================================================================
  75. class ActiveProcess;
  76. friend struct ContainerDeletePolicy<ActiveProcess>;
  77. ScopedPointer<ActiveProcess> activeProcess;
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcess)
  79. };
  80. #endif // JUCE_CHILDPROCESS_H_INCLUDED