swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.29k stars 1.13k forks source link

[SR-4029] Cannot get input in a subprocess started by a Swift program #4550

Open swift-ci opened 7 years ago

swift-ci commented 7 years ago
Previous ID SR-4029
Radar None
Original Reporter axl411 (JIRA User)
Type Bug
Environment Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1) Target: x86_64-apple-macosx10.9
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: fbf53e7562d6b5e0dba637f3057d795d

Issue Description:

In a Swift program, I started a subprocess to run a Ruby script, in the script I expect to get some input.

It works as expected in Xcode, but does not work if I run it in terminal.

This is a demo demonstrating this: https://github.com/axl411/swift-get-input-problem

belkadan commented 7 years ago

I wonder if it's specifically related to using the interpreter. (That is, does running the Xcode-built binary in the Terminal work even though running the script directly doesn't?)

swift-ci commented 7 years ago

Comment by Chao Gu (JIRA)

Just did some tweak to the demo, confirmed that it is not related to the interpreter (running the Xcode-built binary in terminal does not work either).

Here is what I did:

belkadan commented 7 years ago

Interesting. It looks like something is doing an extra level of buffering in Terminal that isn't happening in Xcode. I think I'll have to turn it over to the Foundation folks to figure out the difference.

(My contribution: echo hi | ./main worked fine, as did echo hi | xcrun swift ./main.swift.)