简体   繁体   中英

Using NSTask as root - error: “launch path not accessible”

For some reason when I'm attempting to run a task via NSTask I receive the error message: "launch path not accessible".

My app is running as root. And if I type the EXACT same command in terminal, it runs fine, so I'm a bit confused.

My application copies a tool, called relaunch, to NSTemporaryDirectory() . If I try to run it from here, I get "launch path not accessible". Here is the strange thing, if I manually copy the tool to my desktop, then hardcode the path in NSTask, it will execute properly. And i have 0 idea why.

Anyone know why this is occurring?

Note: Just FYI, trying to get Sparkle to work from github.

Here is the code:

@try{
[NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]];
}

Where

relaunchPath = @"/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/relaunch";

Is the error message coming from your app, or from relaunch? If you haven't changed its standard error to point anywhere else, it will write to the same stderr your app does, so you could actually be launching relaunch successfully and the error message actually be coming from relaunch.

Add an @catch block after your @try to see whether the NSTask actually fails, and check pathToRelaunch .

If you have an @catch block, please edit your question to include it. If it turns out that relaunch is where the failure is happening, but pathToRelaunch looks right, please edit your question to include the relevant source code from the relaunch tool.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM