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.
Run shell script from Objective-C
-
05-12-2021 - |
Frage
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
?
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow