When you run it with absolute paths for the 'swift' and 'python' executables, 
does it work then?

Alex

> On 9 Jan 2017, at 06:20, Mr Bee via swift-users <swift-users@swift.org> wrote:
> 
> Hi,
> 
> I'm writing a simple editor on Linux for Swift language. I use Task (was 
> NSTask) to run the Swift REPL. Unfortunately, Task failed to execute the 
> Swift REPL for no obvious reasons. The Swift compiler and REPL are installed 
> just fine and able to execute any Swift codes. However, my exact same code 
> has no problem to run bash commands.
> 
> Here's the code:
> _____
> 
> import Foundation
> 
> extension Task {
>   func execute(command: String, currentDir: String = "~", arguments: [String] 
> = [], input: String = "") -> String {
>     if !input.isEmpty {
>       let pipeIn = Pipe()
>       self.standardInput = pipeIn
>       // multiple inputs are separated by newline
>       if let input = input.data(using: String.Encoding.utf8) {
>         pipeIn.fileHandleForWriting.write(input)
>       }
>     }
>     
>     let pipeOut = Pipe()
>     self.standardOutput = pipeOut
>     
>     self.arguments = arguments
>     self.launchPath = command
>     self.currentDirectoryPath = currentDir
>     
>     self.launch()
>     let output = pipeOut.fileHandleForReading.readDataToEndOfFile()
>     self.waitUntilExit()
>     
>     return String(data: output, encoding: String.Encoding(rawValue: 
> String.Encoding.utf8.rawValue))!
>   }
> }
> 
> print(Task().execute(command: "swift", arguments: ["test.swift"]))  // <- 
> FAILED
> // print(Task().execute(command: "python", arguments: ["test.py"])) // <- 
> FAILED
> // print(Task().execute(command: "/bin/ls", arguments: ["-l"]))     // <- OK
> 
> _____
> 
> The test code is just a simple hello world program, nothing fancy. Can 
> anybody here enlighten me what did I wrong with the code? I'm using Swift 
> v.3.0 on Ubuntu Linux 14.04.
> 
> Thank you.
> 
> Regards,
> 
> 
> –Mr Bee
> 
> _______________________________________________
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to