I am trying to run the following one line echo bash script using NSUserUnixTask:

echo "hello" >/dev/stderr

The Script file is named TaskLauncher and I have dropped it into my apps code 
signed id folder in NSApplicationScriptsDirectory.
The task fails to launch and com.apple.foundation.UserScriptService crashes 
leaving a report in the console.
I am doing something simple wrong, either that or my expectations are wrong.
There is no sample code for this class.

The error says "Invalid argument" but I don't see what the issue is.

My code is :

            // get scripts folder
            NSURL *scriptsFolderURL = [[NSFileManager defaultManager]
                                       
URLForDirectory:NSApplicationScriptsDirectory
                                       inDomain:NSUserDomainMask
                                       appropriateForURL:nil
                                       create:NO
                                       error:error];
            
            if (*error) {
                MLogInfo(@"Error: %@", *error);
                
                errMsg = NSLocalizedString(@"Cannot access applications scripts 
directory: ", @"Return by server when cannot access application scripts folder 
in sandboxed app.");
                [NSException raise:MGSTaskStartException format:@"%@ %@", 
errMsg, *error];
            }
    
            MLogInfo(@"NSApplicationScriptsDirectory = %@", scriptsFolderURL);
            
            // form task runner path.
            NSString *taskRunnerExec = @"TaskLauncher";
            NSURL *taskRunnerURL = [NSURL fileURLWithPathComponents: 
@[[scriptsFolderURL path], taskRunnerExec]];

            MLogInfo(@"taskRunnerURL = %@", taskRunnerURL);

            // initialise the task
            _unixTask = [[NSUserUnixTask alloc] initWithURL:taskRunnerURL 
error:error];
            if (*error) {
                errMsg = NSLocalizedString(@"Cannot create unix task launcher: 
", @"Return by server when cannot access application scripts task launcher in 
sandboxed app.");
                [NSException raise:MGSTaskStartException format:@"%@ %@", 
errMsg, *error];
                
            }
            
            void (^completionHandler)(NSError *err);
            
            completionHandler = ^(NSError *err) {
                if (err) {
                    NSLog(@"TaskLauncher failed: %@", err);
                } else {
                    NSLog(@"TaskLauncher okay");
                }
            };

            NSArray *taskArguments = @[@"hello", @"task"];
            
            // execute the task.
            [_unixTask executeWithArguments:taskArguments 
completionHandler:completionHandler];


Console Log:

01/12/2012 21:50:33.966 com.apple.foundation.UserScriptService[5931]: *** 
NSTask: Task create for path '/Users/Jonathan/Library/Application 
Scripts/com.mysoft.myapp/TaskLauncher' failed: 22, "Invalid argument".  
Terminating temporary process.

Crash report extract:

Process:         com.apple.foundation.UserScriptService [5931]
Path:            
/System/Library/Frameworks/Foundation.framework/Versions/C/XPCServices/com.apple.foundation.UserScriptService.xpc/Contents/MacOS/com.apple.foundation.UserScriptService
Identifier:      com.apple.foundation.UserScriptService
Version:         6.8 (945.11)
Code Type:       X86-64 (Native)
Parent Process:  com.apple.foundation.UserScriptService [5930]
User ID:         502

Date/Time:       2012-12-01 21:50:33.979 +0000
OS Version:      Mac OS X 10.8.2 (12C54)
Report Version:  10

Crashed Thread:  0  Dispatch queue: com.apple.NSXPCConnection.peer-user.(null)

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000

Application Specific Information:
*** NSTask: Task create for path '/Users/Jonathan/Library/Application 
Scripts/com.mysoft.myapp/TaskLauncher' failed: 22, "Invalid argument".  
Terminating temporary process.

Thread 0 Crashed:: Dispatch queue: com.apple.NSXPCConnection.peer-user.(null)
0   com.apple.Foundation                0x00007fff93ca1258 
___NEW_PROCESS_COULD_NOT_BE_EXECD___ + 5
1   com.apple.Foundation                0x00007fff93b7a911 -[NSConcreteTask 
launchWithDictionary:] + 3544
2   com.apple.Foundation                0x00007fff93d60f59 
-[NSUserScriptTaskRunner 
executeScript:interpreter:arguments:standardInput:standardOutput:standardError::]
 + 794
3   com.apple.CoreFoundation            0x00007fff8912163c __invoking___ + 140
4   com.apple.CoreFoundation            0x00007fff891214d7 -[NSInvocation 
invoke] + 263
5   com.apple.Foundation                0x00007fff93d49751 -[NSXPCConnection 
_decodeAndInvokeMessageWithData:] + 1263
6   com.apple.Foundation                0x00007fff93d4b7da 
__message_handler_block_invoke_0445 + 39
7   libdispatch.dylib                   0x00007fff8aac3f01 
_dispatch_call_block_and_release + 15
8   libdispatch.dylib                   0x00007fff8aac00b6 
_dispatch_client_callout + 8
9   libdispatch.dylib                   0x00007fff8aac147f 
_dispatch_queue_drain + 235
10  libdispatch.dylib                   0x00007fff8aac12f1 
_dispatch_queue_invoke + 52
11  libdispatch.dylib                   0x00007fff8aac11c3 
_dispatch_worker_thread2 + 249
12  libsystem_c.dylib                   0x00007fff8b812cab _pthread_wqthread + 
404
13  libsystem_c.dylib                   0x00007fff8b7fd171 start_wqthread + 13

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x9aad7c2671738043  rbx: 0x00007fc538425520  rcx: 0x00007fc5390011f8  
rdx: 0x00000000a1a1a1a1
  rdi: 0x00007fc5390011f8  rsi: 0x00007fc539001000  rbp: 0x000000010dde75d0  
rsp: 0x000000010dde75d0
   r8: 0x00007fc538427cf0   r9: 0x00000000d3eb2432  r10: 0x0000000000000000  
r11: 0x00000000d3eb2432
  r12: 0x0000000000000000  r13: 0x00007fc539804d40  r14: 0x00007fff7a6fcaf0  
r15: 0x00007fff93462240
  rip: 0x00007fff93ca1258  rfl: 0x0000000000000202  cr2: 0x000000010db01000

Binary Images:
       0x10db48000 -        0x10db48fff  com.apple.foundation.UserScriptService 
(6.8 - 945.11) <27791669-FEED-3082-80F6-5C5793EFFF50> 
/System/Library/Frameworks/Foundation.framework/Versions/C/XPCServices/com.apple.foundation.UserScriptService.xpc/Contents/MacOS/com.apple.foundation.UserScriptService
    0x7fff6d748000 -     0x7fff6d77c93f  dyld (210.2.3) 
<A40597AA-5529-3337-8C09-D8A014EB1578> /usr/lib/dyld
    0x7fff88e6d000 -     0x7fff89008fef  com.apple.vImage (6.0 - 6.0) 
<FAE13169-295A-33A5-8E6B-7C2CC1407FA7> 
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage
    0x7fff89064000 -     0x7fff8909afff  com.apple.DebugSymbols (98 - 98) 
<14E788B1-4EB2-3FD7-934B-849534DFC198> 
/System/Library/PrivateFrameworks/DebugSymbols.framework/Versions/A/DebugSymbols
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to