OpenShot Audio Library | OpenShotAudio
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
juce_ChildProcess.cpp
1
/*
2
==============================================================================
3
4
This file is part of the JUCE library.
5
Copyright (c) 2022 - Raw Material Software Limited
6
7
JUCE is an open source library subject to commercial or open-source
8
licensing.
9
10
The code included in this file is provided under the terms of the ISC license
11
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12
To use, copy, modify, and/or distribute this software for any purpose with or
13
without fee is hereby granted provided that the above copyright notice and
14
this permission notice appear in all copies.
15
16
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18
DISCLAIMED.
19
20
==============================================================================
21
*/
22
23
namespace
juce
24
{
25
26
ChildProcess::ChildProcess
() {}
27
ChildProcess::~ChildProcess
() {}
28
29
bool
ChildProcess::isRunning
()
const
30
{
31
return
activeProcess !=
nullptr
&& activeProcess->isRunning();
32
}
33
34
int
ChildProcess::readProcessOutput
(
void
* dest,
int
numBytes)
35
{
36
return
activeProcess !=
nullptr
? activeProcess->read (dest, numBytes) : 0;
37
}
38
39
bool
ChildProcess::kill
()
40
{
41
return
activeProcess ==
nullptr
|| activeProcess->killProcess();
42
}
43
44
uint32
ChildProcess::getExitCode
()
const
45
{
46
return
activeProcess !=
nullptr
? activeProcess->getExitCode() : 0;
47
}
48
49
bool
ChildProcess::waitForProcessToFinish
(
const
int
timeoutMs)
const
50
{
51
auto
timeoutTime =
Time::getMillisecondCounter
() + (uint32) timeoutMs;
52
53
do
54
{
55
if
(!
isRunning
())
56
return
true
;
57
58
Thread::sleep
(2);
59
}
60
while
(timeoutMs < 0 ||
Time::getMillisecondCounter
() < timeoutTime);
61
62
return
false
;
63
}
64
65
String
ChildProcess::readAllProcessOutput
()
66
{
67
MemoryOutputStream
result;
68
69
for
(;;)
70
{
71
char
buffer[512];
72
auto
num =
readProcessOutput
(buffer,
sizeof
(buffer));
73
74
if
(num <= 0)
75
break
;
76
77
result.
write
(buffer, (
size_t
) num);
78
}
79
80
return
result.
toString
();
81
}
82
83
84
//==============================================================================
85
//==============================================================================
86
#if JUCE_UNIT_TESTS
87
88
class
ChildProcessTests final :
public
UnitTest
89
{
90
public
:
91
ChildProcessTests()
92
:
UnitTest
(
"ChildProcess"
, UnitTestCategories::threads)
93
{}
94
95
void
runTest()
override
96
{
97
beginTest (
"Child Processes"
);
98
99
#if JUCE_WINDOWS || JUCE_MAC || JUCE_LINUX || JUCE_BSD
100
ChildProcess p;
101
102
#if JUCE_WINDOWS
103
expect (p.start (
"tasklist"
));
104
#else
105
expect (p.start (
"ls /"
));
106
#endif
107
108
auto
output = p.readAllProcessOutput();
109
expect (output.isNotEmpty());
110
#endif
111
}
112
};
113
114
static
ChildProcessTests childProcessUnitTests;
115
116
#endif
117
118
}
// namespace juce
juce::ChildProcess::getExitCode
uint32 getExitCode() const
Definition
juce_ChildProcess.cpp:44
juce::ChildProcess::readAllProcessOutput
String readAllProcessOutput()
Definition
juce_ChildProcess.cpp:65
juce::ChildProcess::readProcessOutput
int readProcessOutput(void *destBuffer, int numBytesToRead)
Definition
juce_ChildProcess.cpp:34
juce::ChildProcess::~ChildProcess
~ChildProcess()
Definition
juce_ChildProcess.cpp:27
juce::ChildProcess::isRunning
bool isRunning() const
Definition
juce_ChildProcess.cpp:29
juce::ChildProcess::waitForProcessToFinish
bool waitForProcessToFinish(int timeoutMs) const
Definition
juce_ChildProcess.cpp:49
juce::ChildProcess::kill
bool kill()
Definition
juce_ChildProcess.cpp:39
juce::ChildProcess::ChildProcess
ChildProcess()
Definition
juce_ChildProcess.cpp:26
juce::MemoryOutputStream
Definition
juce_MemoryOutputStream.h:36
juce::MemoryOutputStream::toString
String toString() const
Definition
juce_MemoryOutputStream.cpp:195
juce::MemoryOutputStream::write
bool write(const void *, size_t) override
Definition
juce_MemoryOutputStream.cpp:102
juce::String
Definition
juce_String.h:53
juce::Thread::sleep
static void JUCE_CALLTYPE sleep(int milliseconds)
juce::Time::getMillisecondCounter
static uint32 getMillisecondCounter() noexcept
Definition
juce_Time.cpp:241
juce::UnitTest
Definition
juce_UnitTest.h:70
libopenshot-audio
JuceLibraryCode
modules
juce_core
threads
juce_ChildProcess.cpp
Generated by
1.18.0