I need to launch and execute a task via NSTask and then immediately get both 
notification that it launched, and it's launched pid.

I tried the notification mechanism but it requires that I first return from my 
launch function and let the even loop run in order to receive the notification. 
If there some other way to get the notification immediately after launch. I 
tried the following:

// Make params array...
                    
                    launchTaskParams = [ [ NSArray alloc ] initWithArray:[ 
NSArray arrayWithObject:finalPathMutableNSString ] ];
                    
                    // Make task...
                    
                    launchTask = [ [ NSTask alloc ] init ];
                    
                    if( launchTask && launchTaskParams )
                    {
                        // Set arguments & path...
                        
                        [ launchTask setArguments:launchTaskParams ];
                        
                        [ launchTask setLaunchPath:finalPathMutableNSString ];
                        
                        // Launch!
                        
                        [ launchTask launch ];
                        
                        // Wait 'til  is running...
                        
                        while( ![ launchTask isRunning ] )
                        {
                            ;    // Spin
                        }
                        
                        // Set pid in output...
                        
                        lppiProcInfo->dwProcessId = (DWORD)[ LaunchTask 
processIdentifier ];
                        
                        NSLog( @"PID is: @%", [ [ NSNumber numberWithInt:[ 
LaunchTask processIdentifier ] ] stringValue ] );
                        
                        // Release the LaunchTask & params so they can be used 
next time...
                
                        [ launchTask release ];
                
                        [ launchTaskParams release ];
                }



      
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to