سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top