ChildProcess::start failing with spaces in the path


#1

Hi,

I'm launching a command-line program (Perforce) from within a JUCE application and want to process the output of that program.  I do this by creating a ChildProcess and calling start() on it, then periodically calling readProcessOutput() to update a string containing the resulting output.  I do this rather than calling readAllProcessOutput() because some commands take a while to complete so I run this in another thread and pass the updates back to the GUI thread via a message.

I place the filename of the executable in quotes to safe-guard against spaces in the path, and this works on Windows but on OSX I am experiencing a problem.  If the path to the executable includes a space, the call to start() doesn't return an error, but the child process fails to launch and the output contains a stream of JUCE errors from the LeakedObjectDetector.

This same error occurs if the program being launched can't be found.  I've put a check in my code for missing programs, but there are some programs I need to call that include a space in the path.  Does anybody know a way of working around this?

Thanks,

Charles


#2

You shouldn't actually need to add quotes - the classes should add them for you if it needs them.

The leaks sound a bit strange though - can you give us some sample code that reproduces the problem?


#3

Using the Helloworld example, I placed the following code in the HelloWorldWindow constructor, right at the end, just after the call to setVisible():

        ChildProcess cp;
        cp.start( "invalid_command" );
        String sOutput = cp.readAllProcessOutput();
        Logger::outputDebugString( sOutput );

The only other change I made was to set the Deployment Target to 10.8 (as that's the version of OSX I'm running on).


#4

Hmm.. tried it here and no leaks. There's also nothing in the code that looks like it could leak. I think maybe in your code you're somehow exiting before the ChildProcess object is deleted?


#5

Hi Jules,

Thanks for checking.  I've just tested and it's the same with our raw code drop for me, but it looks like we haven't updated since September last year.  I'll get the latest version and try again.

Charles


#6

Hi, 

I've just downloaded the current build from GitHub and made the same change as I mentioned above, and this is the output I get:

JUCE v3.1.1
*** Leaked objects detected: 1 instance(s) of class ActiveProcess
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ChildProcess
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 2 instance(s) of class OSXTypeface
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 2 instance(s) of class Typeface
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class TextButton
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class Label
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class Font
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class TypefaceCache
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class MainComponent
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class KeyPress
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ButtonListenerProxy
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 3 instance(s) of class GlassWindowButton
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 4 instance(s) of class CallbackHelper
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 4 instance(s) of class Button
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 5 instance(s) of class SimpleValueSource
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 5 instance(s) of class ValueSource
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 7 instance(s) of class Path
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class LookAndFeel_V2
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class LookAndFeel
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class DocumentWindow
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ResizableWindow
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ComponentBoundsConstrainer
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ComponentDragger
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class TimerThread
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class Thread
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 3 instance(s) of class WaitableEvent
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class NSViewComponentPeer
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ComponentPeer
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class DisplaySettingsChangeCallback
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class Desktop
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ComponentAnimator
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class MouseInputSource
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class MouseInputSourceInternal
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 10 instance(s) of class AsyncUpdater
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class TopLevelWindow
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 7 instance(s) of class Component
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 7 instance(s) of class MouseCursor
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class ApplicationCommandTarget
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class MessageManager
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class Image
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 2 instance(s) of class AffineTransform
JUCE Assertion failure in juce_LeakedObjectDetector.h:95
*** Leaked objects detected: 1 instance(s) of class StringArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:95

I'm running on OSX 10.8.5 with XCode 5.0.1 and other than change the Deployment Target to 10.8 I've made no other changes to the JUCE code.

I've bypassed my original problem by swapping to use the StringArray version of ChildProcess::start() but that doesn't fix the underlying issue.

Charles


#7

Nope, I tried that code in the hello world app, and had no leaks.

That log means that your app isn't actually shutting down properly or deleting its window. You must be doing something that you've not mentioned in this thread to cause it to quit suddenly or not clean up.