Last active
June 13, 2023 19:11
-
-
Save backslash-f/02a25d10cbb8d8ff9038bf50728da162 to your computer and use it in GitHub Desktop.
Revisions
-
Fernando Fernandes revised this gist
Jan 26, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,4 +19,5 @@ func shell(_ command: String) { shell("export MY_VAR=123 ; echo $MY_VAR") // In CLI: // chmod a+x Shell.swift // ./Shell.swift -
Fernando Fernandes revised this gist
Jan 26, 2020 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,3 +17,6 @@ func shell(_ command: String) { } shell("export MY_VAR=123 ; echo $MY_VAR") // In CLI: // ./Shell.swift -
Fernando Fernandes created this gist
Jan 26, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #!/usr/bin/swift import Foundation func shell(_ command: String) { let task = Process() task.launchPath = "/bin/zsh" task.arguments = ["-c", command] let pipe = Pipe() task.standardOutput = pipe task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = String(data: data, encoding: .utf8) ?? "" print(output) } shell("export MY_VAR=123 ; echo $MY_VAR")