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.

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