문제

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