Skip to content

Commit 3b86857

Browse files
authored
Merge pull request #8 from leonvictor/childprocess_commandline_args
Add a method to launch a child worker process while passing it additionnal command line arguments
2 parents ae44fa0 + 966e637 commit 3b86857

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,28 @@ bool ChildProcessCoordinator::sendMessageToWorker (const MemoryBlock& mb)
155155

156156
bool ChildProcessCoordinator::launchWorkerProcess (const File& executable, const String& commandLineUniqueID,
157157
int timeoutMs, int streamFlags)
158+
{
159+
StringArray args;
160+
args.add (executable.getFullPathName());
161+
162+
return launchWorkerProcess(args, commandLineUniqueID, timeoutMs, streamFlags);
163+
}
164+
165+
bool ChildProcessCoordinator::launchWorkerProcess(const StringArray& arguments, const String& commandLineUniqueID,
166+
int timeoutMs, int streamFlags)
158167
{
159168
killWorkerProcess();
160169

161-
auto pipeName = "p" + String::toHexString (Random().nextInt64());
170+
auto pipeName = "p" + String::toHexString(Random().nextInt64());
162171

163172
StringArray args;
164-
args.add (executable.getFullPathName());
165-
args.add (getCommandLinePrefix (commandLineUniqueID) + pipeName);
173+
args.add(arguments[0]);
174+
args.add(getCommandLinePrefix(commandLineUniqueID) + pipeName);
175+
if (arguments.size() > 1)
176+
{
177+
args.addArray(arguments.begin() + 1, arguments.end());
178+
}
179+
166180

167181
childProcess = [&]() -> std::shared_ptr<ChildProcess>
168182
{

modules/juce_events/interprocess/juce_ConnectedChildProcess.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,32 @@ class JUCE_API ChildProcessCoordinator
174174
int timeoutMs = 0,
175175
int streamFlags = ChildProcess::wantStdOut | ChildProcess::wantStdErr);
176176

177+
/** Attempts to launch and connect to a worker process by command line.
178+
179+
The first argument should be the name of the executable file, followed by any other
180+
arguments that are needed.
181+
This will start the given executable, passing it a special command-line
182+
parameter as first argument based around the commandLineUniqueID string, which must be a
183+
short alphanumeric string (no spaces!) that identifies your app. The exe
184+
that gets launched must respond by calling ChildProcessWorker::initialiseFromCommandLine()
185+
in its startup code, and must use a matching ID to commandLineUniqueID.
186+
187+
The timeoutMs parameter lets you specify how long the child process is allowed
188+
to go without sending a ping before it is considered to have died and
189+
handleConnectionLost() will be called. Passing <= 0 for this timeout makes
190+
it use a default value.
191+
192+
If this all works, the method returns true, and you can begin sending and
193+
receiving messages with the worker process.
194+
195+
If a child process is already running, this will call killWorkerProcess() and
196+
start a new one.
197+
*/
198+
bool launchWorkerProcess(const StringArray& arguments,
199+
const String& commandLineUniqueID,
200+
int timeoutMs = 0,
201+
int streamFlags = ChildProcess::wantStdOut | ChildProcess::wantStdErr);
202+
177203
[[deprecated ("Replaced by launchWorkerProcess.")]]
178204
bool launchSlaveProcess (const File& executableToLaunch,
179205
const String& commandLineUniqueID,

0 commit comments

Comments
 (0)