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.

96 lines
2.5KB

  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. BEGIN_JUCE_NAMESPACE
  19. ChildProcess::ChildProcess() {}
  20. ChildProcess::~ChildProcess() {}
  21. bool ChildProcess::waitForProcessToFinish (const int timeoutMs) const
  22. {
  23. const int64 timeoutTime = Time::getMillisecondCounter() + timeoutMs;
  24. do
  25. {
  26. if (! isRunning())
  27. return true;
  28. }
  29. while (timeoutMs < 0 || Time::getMillisecondCounter() < timeoutTime);
  30. return false;
  31. }
  32. String ChildProcess::readAllProcessOutput()
  33. {
  34. MemoryOutputStream result;
  35. for (;;)
  36. {
  37. char buffer [512];
  38. const int num = readProcessOutput (buffer, sizeof (buffer));
  39. if (num <= 0)
  40. break;
  41. result.write (buffer, num);
  42. }
  43. return result.toString();
  44. }
  45. //==============================================================================
  46. #if JUCE_UNIT_TESTS
  47. class ChildProcessTests : public UnitTest
  48. {
  49. public:
  50. ChildProcessTests() : UnitTest ("ChildProcess") {}
  51. void runTest()
  52. {
  53. beginTest ("Child Processes");
  54. #if JUCE_WINDOWS || JUCE_MAC || JUCE_LINUX
  55. ChildProcess p;
  56. #if JUCE_WINDOWS
  57. expect (p.start ("tasklist"));
  58. #else
  59. expect (p.start ("ls /"));
  60. #endif
  61. String output (p.readAllProcessOutput());
  62. expect (output.isNotEmpty());
  63. #endif
  64. }
  65. };
  66. static ChildProcessTests childProcessUnitTests;
  67. #endif
  68. END_JUCE_NAMESPACE