OpenShot Library | OpenShotAudio  0.2.1
juce_ChildProcess.h
1 
2 /** @weakgroup juce_core-threads
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Launches and monitors a child process.
33 
34  This class lets you launch an executable, and read its output. You can also
35  use it to check whether the child process has finished.
36 
37  @tags{Core}
38 */
40 {
41 public:
42  //==============================================================================
43  /** Creates a process object.
44  To actually launch the process, use start().
45  */
46  ChildProcess();
47 
48  /** Destructor.
49  Note that deleting this object won't terminate the child process.
50  */
51  ~ChildProcess();
52 
53  /** These flags are used by the start() methods. */
55  {
56  wantStdOut = 1,
57  wantStdErr = 2
58  };
59 
60  /** Attempts to launch a child process command.
61 
62  The command should be the name of the executable file, followed by any arguments
63  that are required.
64  If the process has already been launched, this will launch it again. If a problem
65  occurs, the method will return false.
66  The streamFlags is a combinations of values to indicate which of the child's output
67  streams should be read and returned by readProcessOutput().
68  */
69  bool start (const String& command, int streamFlags = wantStdOut | wantStdErr);
70 
71  /** Attempts to launch a child process command.
72 
73  The first argument should be the name of the executable file, followed by any other
74  arguments that are needed.
75  If the process has already been launched, this will launch it again. If a problem
76  occurs, the method will return false.
77  The streamFlags is a combinations of values to indicate which of the child's output
78  streams should be read and returned by readProcessOutput().
79  */
80  bool start (const StringArray& arguments, int streamFlags = wantStdOut | wantStdErr);
81 
82  /** Returns true if the child process is alive. */
83  bool isRunning() const;
84 
85  /** Attempts to read some output from the child process.
86  This will attempt to read up to the given number of bytes of data from the
87  process. It returns the number of bytes that were actually read.
88  */
89  int readProcessOutput (void* destBuffer, int numBytesToRead);
90 
91  /** Blocks until the process has finished, and then returns its complete output
92  as a string.
93  */
94  String readAllProcessOutput();
95 
96  /** Blocks until the process is no longer running. */
97  bool waitForProcessToFinish (int timeoutMs) const;
98 
99  /** If the process has finished, this returns its exit code. */
100  uint32 getExitCode() const;
101 
102  /** Attempts to kill the child process.
103  Returns true if it succeeded. Trying to read from the process after calling this may
104  result in undefined behaviour.
105  */
106  bool kill();
107 
108 private:
109  //==============================================================================
110  class ActiveProcess;
111  std::unique_ptr<ActiveProcess> activeProcess;
112 
113  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcess)
114 };
115 
116 } // namespace juce
117 
118 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
A special array for holding a list of strings.
The JUCE String class!
Definition: juce_String.h:42
Launches and monitors a child process.
StreamFlags
These flags are used by the start() methods.