<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yiv4250953375"><div id="yui_3_16_0_ym19_1_1483940019235_61653"><div style="color:#000;background-color:#fff;font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;" id="yui_3_16_0_ym19_1_1483940019235_61652"><div><span></span></div><div></div><div id="yui_3_16_0_ym19_1_1483940019235_61651">Hi,</div><div id="yui_3_16_0_ym19_1_1483940019235_61651"><br></div><div id="yui_3_16_0_ym19_1_1483940019235_61651"><div dir="ltr" id="yui_3_16_0_ym19_1_1483940019235_65599"><span id="yui_3_16_0_ym19_1_1483940019235_65600">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.</span></div><div dir="ltr" id="yui_3_16_0_ym19_1_1483940019235_65601"><br id="yui_3_16_0_ym19_1_1483940019235_65602"></div><div dir="ltr" id="yui_3_16_0_ym19_1_1483940019235_65603">Here's the code:</div></div><div id="yui_3_16_0_ym19_1_1483940019235_61651">_____</div><div id="yui_3_16_0_ym19_1_1483940019235_61651"><br></div><div id="yui_3_16_0_ym19_1_1483940019235_61651"><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62655"><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62656">import</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62657"> Foundation</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 119, 66);" id="yui_3_16_0_ym19_1_1483940019235_62658"><br></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);" id="yui_3_16_0_ym19_1_1483940019235_62664"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62665">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62666"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62667">Task</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62668"> {</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62669"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62670">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62671">func</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62672"> execute(command: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62673">String</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62674">, currentDir: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62675">String</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62676"> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #e82300" id="yui_3_16_0_ym19_1_1483940019235_62677">"~"</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62678">, arguments: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62679">String</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62680">] = [], input: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62681">String</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62682"> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #e82300" id="yui_3_16_0_ym19_1_1483940019235_62683">""</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62684">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62685">String</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62686"> {</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62687"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62688">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62689">if</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62690"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" id="yui_3_16_0_ym19_1_1483940019235_62691">!</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62692">input.</span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" id="yui_3_16_0_ym19_1_1483940019235_62693">isEmpty</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62694"> {</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62695"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62696">&nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62697">let</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62698"> pipeIn = </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62699">Pipe</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62700">()</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62701"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62702">&nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62703">self</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62704">.standardInput = pipeIn</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 119, 66);" id="yui_3_16_0_ym19_1_1483940019235_62705"><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62706">&nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62707"><i id="yui_3_16_0_ym19_1_1483940019235_62708">// multiple inputs are separated by newline</i></span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62709"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62710">&nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62711">if</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62712"> </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62713">let</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62714"> input = input.</span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" id="yui_3_16_0_ym19_1_1483940019235_62715">data</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62716">(using: </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62717">String</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62718">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62719">Encoding</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62720">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" id="yui_3_16_0_ym19_1_1483940019235_62721">utf8</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62722">) {</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168);" id="yui_3_16_0_ym19_1_1483940019235_62723"><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62724">&nbsp; &nbsp; &nbsp; &nbsp; pipeIn.</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62725">fileHandleForWriting</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62726">.</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62727">write</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62728">(input)</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62729"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62730">&nbsp; &nbsp; &nbsp; }</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62731"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62732">&nbsp; &nbsp; }</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" id="yui_3_16_0_ym19_1_1483940019235_62733"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62734">&nbsp;&nbsp; &nbsp;</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62735"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62736">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62737">let</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62738"> pipeOut = </span><span style="font-variant-ligatures: no-common-ligatures; color: #c35900" id="yui_3_16_0_ym19_1_1483940019235_62739">Pipe</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62740">()</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62741"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62742">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62743">self</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62744">.standardOutput = pipeOut</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" id="yui_3_16_0_ym19_1_1483940019235_62745"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62746">&nbsp;&nbsp; &nbsp;</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62747"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62748">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62749">self</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62750">.arguments = arguments</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62751"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62752">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62753">self</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62754">.launchPath = command</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62755"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62756">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62757">self</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62758">.currentDirectoryPath = currentDir</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" id="yui_3_16_0_ym19_1_1483940019235_62759"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62760">&nbsp;&nbsp; &nbsp;</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62761"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62762">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62763">self</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62764">.launch()</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168);" id="yui_3_16_0_ym19_1_1483940019235_62765"><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62766">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62767">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62768"> output = pipeOut.</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62769">fileHandleForReading</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62770">.</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62771">readDataToEndOfFile</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" id="yui_3_16_0_ym19_1_1483940019235_62772">()</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62773"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62774">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62775">self</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62776">.waitUntilExit()</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" id="yui_3_16_0_ym19_1_1483940019235_62777"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62778">&nbsp;&nbsp; &nbsp;</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62779"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62780">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" id="yui_3_16_0_ym19_1_1483940019235_62781">return</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62782"> String(data: output, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))!</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62783"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62784">&nbsp; }</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62785"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62786">}</span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" id="yui_3_16_0_ym19_1_1483940019235_62787"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62788"></span><br id="yui_3_16_0_ym19_1_1483940019235_62789"></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62790"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62791">print(Task().execute(command: </span><span style="font-variant-ligatures: no-common-ligatures; color: #e82300" id="yui_3_16_0_ym19_1_1483940019235_62792">"swift"</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62793">, arguments: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #e82300" id="yui_3_16_0_ym19_1_1483940019235_62794">"test.swift"</span><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62795">]))&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #007742" id="yui_3_16_0_ym19_1_1483940019235_62796"><i id="yui_3_16_0_ym19_1_1483940019235_62797">// &lt;- FAILED</i></span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 119, 66);" id="yui_3_16_0_ym19_1_1483940019235_62798"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62799"><i id="yui_3_16_0_ym19_1_1483940019235_62800">// print(Task().execute(command: "python", arguments: ["test.py"])) // &lt;- FAILED</i></span></div><div style="font-size: 12px; line-height: normal; font-family: Menlo;" id="yui_3_16_0_ym19_1_1483940019235_62129">






























</div><div style="font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 119, 66);" id="yui_3_16_0_ym19_1_1483940019235_62801"><span style="font-variant-ligatures: no-common-ligatures" id="yui_3_16_0_ym19_1_1483940019235_62802"><i id="yui_3_16_0_ym19_1_1483940019235_62803">// print(Task().execute(command: "/bin/ls", arguments: ["-l"])) &nbsp; &nbsp; // &lt;- OK</i></span></div><div dir="ltr" id="yui_3_16_0_ym19_1_1483940019235_62804"><br></div></div><div id="yui_3_16_0_ym19_1_1483940019235_61651" dir="ltr">_____</div><div id="yui_3_16_0_ym19_1_1483940019235_61651" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1483940019235_61651">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.</div><div id="yui_3_16_0_ym19_1_1483940019235_61651"><br></div><div id="yui_3_16_0_ym19_1_1483940019235_61651">Thank you.</div><div id="yui_3_16_0_ym19_1_1483940019235_61651"><br></div><div id="yui_3_16_0_ym19_1_1483940019235_61651">Regards,</div><div id="yui_3_16_0_ym19_1_1483940019235_61651"><br></div><div class="yiv4250953375signature" id="yui_3_16_0_ym19_1_1483940019235_61655"><div id="yui_3_16_0_ym19_1_1483940019235_61654"><br></div>–Mr Bee<div id="yui_3_16_0_ym19_1_1483940019235_65806"><br></div></div></div></div></div></div></body></html>