JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ChildProcess Class Reference

Launches and monitors a child process. More...

#include <juce_ChildProcess.h>

Collaboration diagram for juce::ChildProcess:

Classes

class  ActiveProcess
 

Public Types

enum  StreamFlags {
  wantStdOut = 1,
  wantStdErr = 2
}
 These flags are used by the start() methods. More...
 

Public Member Functions

 ChildProcess ()
 Creates a process object. More...
 
 ~ChildProcess ()
 Destructor. More...
 
uint32 getExitCode () const
 If the process has finished, this returns its exit code. More...
 
bool isRunning () const
 Returns true if the child process is alive. More...
 
bool kill ()
 Attempts to kill the child process. More...
 
String readAllProcessOutput ()
 Blocks until the process has finished, and then returns its complete output as a string. More...
 
int readProcessOutput (void *destBuffer, int numBytesToRead)
 Attempts to read some output from the child process. More...
 
bool start (const String &command, int streamFlags=wantStdOut|wantStdErr)
 Attempts to launch a child process command. More...
 
bool start (const StringArray &arguments, int streamFlags=wantStdOut|wantStdErr)
 Attempts to launch a child process command. More...
 
bool waitForProcessToFinish (int timeoutMs) const
 Blocks until the process is no longer running. More...
 

Private Attributes

std::unique_ptr< ActiveProcessactiveProcess
 

Detailed Description

Launches and monitors a child process.

This class lets you launch an executable, and read its output. You can also use it to check whether the child process has finished.

{Core}

Member Enumeration Documentation

◆ StreamFlags

These flags are used by the start() methods.

Enumerator
wantStdOut 
wantStdErr 

Constructor & Destructor Documentation

◆ ChildProcess()

juce::ChildProcess::ChildProcess ( )

Creates a process object.

To actually launch the process, use start().

◆ ~ChildProcess()

juce::ChildProcess::~ChildProcess ( )

Destructor.

Note that deleting this object won't terminate the child process.

Member Function Documentation

◆ getExitCode()

uint32 juce::ChildProcess::getExitCode ( ) const

If the process has finished, this returns its exit code.

◆ isRunning()

bool juce::ChildProcess::isRunning ( ) const

Returns true if the child process is alive.

◆ kill()

bool juce::ChildProcess::kill ( )

Attempts to kill the child process.

Returns true if it succeeded. Trying to read from the process after calling this may result in undefined behaviour.

◆ readAllProcessOutput()

String juce::ChildProcess::readAllProcessOutput ( )

Blocks until the process has finished, and then returns its complete output as a string.

◆ readProcessOutput()

int juce::ChildProcess::readProcessOutput ( void *  destBuffer,
int  numBytesToRead 
)

Attempts to read some output from the child process.

This will attempt to read up to the given number of bytes of data from the process. It returns the number of bytes that were actually read.

◆ start() [1/2]

bool juce::ChildProcess::start ( const String command,
int  streamFlags = wantStdOut | wantStdErr 
)

Attempts to launch a child process command.

The command should be the name of the executable file, followed by any arguments that are required. If the process has already been launched, this will launch it again. If a problem occurs, the method will return false. The streamFlags is a combinations of values to indicate which of the child's output streams should be read and returned by readProcessOutput().

References juce::StringArray::fromTokens().

◆ start() [2/2]

bool juce::ChildProcess::start ( const StringArray arguments,
int  streamFlags = wantStdOut | wantStdErr 
)

Attempts to launch a child process command.

The first argument should be the name of the executable file, followed by any other arguments that are needed. If the process has already been launched, this will launch it again. If a problem occurs, the method will return false. The streamFlags is a combinations of values to indicate which of the child's output streams should be read and returned by readProcessOutput().

References juce::StringArray::size().

◆ waitForProcessToFinish()

bool juce::ChildProcess::waitForProcessToFinish ( int  timeoutMs) const

Blocks until the process is no longer running.

Member Data Documentation

◆ activeProcess

std::unique_ptr<ActiveProcess> juce::ChildProcess::activeProcess
private

The documentation for this class was generated from the following files: