[swift-users] Start another program from Swift script

Michael Ilseman milseman at apple.com
Thu Jan 4 14:45:43 CST 2018


The “Shell Out” package’s source code shows some simple usage of Foundation’s Process: https://github.com/JohnSundell/ShellOut/blob/master/Sources/ShellOut.swift#L33. 

That package also handles stdout / stdin, but for more sophisticated uses of FileManager the “Files” package’s source has some nice simple usage: https://github.com/JohnSundell/Files/blob/master/Sources/Files.swift


> On Jan 4, 2018, at 10:31 AM, Karl Wagner via swift-users <swift-users at swift.org> wrote:
> 
> These kinds of things live in Foundation, not the standard library:
> 
> import Foundation
> 
> let p = Process()
> p.executableURL = URL(fileURLWithPath: "/bin/ps")
> try p.run()
> 
> The Process class provides you with stdin/out/error handles for the process (https://developer.apple.com/documentation/foundation/process <https://developer.apple.com/documentation/foundation/process>).
> FileHandle also provides these standard streams for the current process (https://developer.apple.com/documentation/foundation/filehandle <https://developer.apple.com/documentation/foundation/filehandle>).
> 
> - Karl
> 
>> On 4. Jan 2018, at 17:03, Седых Александр via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> 
>> Well, for example in Python we can run another program from interpreter by
>>  
>> import subprocess
>> result = subprocess.run('ruby script.rb').stdout
>>  
>> My question is next:
>> Can we do something from Swift file at runtime or maybe from terminal via REPL
>>  
>> And can you send me resource when I can read about work with stdin, stdout in Swift, because is very small info in Documentation (Standard Library I/O)
>> 
>> -
>> Alexandr
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org <mailto:swift-users at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20180104/c48a2a3c/attachment.html>


More information about the swift-users mailing list