2014-08-28 11 views
8

Sto cercando di eseguire uno script di shell con NSTask con il seguente codice:esecuzione di script di shell con NSTask provoca l'errore posix_spawn

NSTask *task = [[NSTask alloc] init]; 
[task setLaunchPath:@"/Users/username/connect.sh"]; 
[task launch]; 

ma ottengo An uncaught exception was raised e Couldn't posix_spawn: error 8

Se ho appena eseguito lo script nel terminale, tutto funziona.

Ecco cosa lo script contiene:

if [ ! -d ~/Remote/username/projects ] 
then 
     sshfs -C -p 22 [email protected]:/home/username ~/Remote/username   
fi 

risposta

2

è necessario utilizzare setLaunchPath come questo:

[task setLaunchPath:@"/bin/sh"]; 

Quindi utilizzare setArguments per lo script:

[task setArguments: [NSArray arrayWithObjects: @"~/connect.sh", nil]]; 
2

È inoltre possibile aggiungi #!/bin/bash all'inizio del tuo script:

#!/bin/bash 

if [ ! -d ~/Remote/username/projects ] 
then 
    sshfs -C -p 22 [email protected]:/home/username  ~/Remote/username   
fi 
Problemi correlati