3

I'm trying to run a shell script that is in an NSTextView. I know I can use NSTask to do this, but I was wondering what the best way would be, if the script only exists in memory (the text view) but not on disk.

Should I temporarily write it to disk or somehow run it directly as string?

And what parameters do I pass to NSTask? Do I have to extract the shebang line and pass it as launchPath?

1
  • You can pass the parameters using a NSArray, see the setArguments method (or directly use launchedTaskWithLaunchPath:arguments:). Commented Dec 5, 2012 at 23:33

1 Answer 1

5

You can execute /bin/bash as your NSTask, and setStandardInput to an NSPipe. Then write the NSString containing your script to the pipe via its fileHandleForWriting to avoid creating a file on disk.

Sign up to request clarification or add additional context in comments.

1 Comment

does the NSSString has to be UTF-8 encoded? NSFileHandleForWriting takes an NSData.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.