1

I want to run a shell script using NSTask. This script is designed such that it will first come out from its current operation (cd ..) then will perform other operations.

So two tasks needs to be performed using NSTask go to the directory where script is present using cd and then run shell script. I am using below code but its its launch path not accessible error.

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath:@"/bin/true"];
[task setArguments:[NSArray arrayWithObject:@"cd /Users/user/work/project_4th_Jul 3/DemoWork/scripts ; sh Demoinstaller.sh"]];

[task launch];

Any ideas how to achieve this.

Wain
  • 118,658
  • 15
  • 128
  • 151
Akhil Shrivastav
  • 427
  • 3
  • 13
  • If you need to you can also use other methods on `NSTask`, such as `setCurrentDirectoryPath:` – Wain Jul 08 '14 at 10:33
  • @wain launch path is different for cd and sh and this is the issue. for same launch path [link](http://stackoverflow.com/questions/17976289/executing-shell-commands-with-nstask-objective-c-cocoa) can be referred. – Akhil Shrivastav Jul 08 '14 at 10:37
  • 2
    You should not be launching `cd`, `cd` just sets the working directory, hence you should use `setCurrentDirectoryPath:` – Wain Jul 08 '14 at 10:41

0 Answers0