I'm trying to run a shell script with NSTask with the following code:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/Users/username/connect.sh"];
[task launch];
But I get An uncaught exception was raised
and Couldn't posix_spawn: error 8
If I just run the script in terminal, everything works.
Here is what the script contains:
if [ ! -d ~/Remote/username/projects ]
then
sshfs -C -p 22 [email protected]:/home/username ~/Remote/username
fi
You can also add #!/bin/bash
to the start of your script:
#!/bin/bash
if [ ! -d ~/Remote/username/projects ]
then
sshfs -C -p 22 [email protected]:/home/username ~/Remote/username
fi
You need to use setLaunchPath like this:
[task setLaunchPath:@"/bin/sh"];
Then use setArguments for your script:
[task setArguments: [NSArray arrayWithObjects: @"~/connect.sh", nil]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With