Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-15097] [swift-tools-support-core] TSCBasic.Process does not wait for readLine input. #4391

Open
swift-ci opened this issue Aug 20, 2021 · 4 comments
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-15097
Radar rdar://problem/82178262
Original Reporter beepluis (JIRA User)
Type Bug
Environment
> xcodebuild -version
Xcode 12.5.1
Build version 12E507
> swift --version
Apple Swift version 5.4.2 (swiftlang-1205.0.28.2 clang-1205.0.19.57)
Target: x86_64-apple-darwin20.6.0
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 2402872cb77832cf2be5b6a466e5f1ea

Issue Description:

This is a bug report for project: https://github.com/apple/swift-tools-support-core

Summary:

When using `TSCBasic.Process` to run an external executable that uses `readLine` to read user input, the process does not wait for input and instead exits causing issues.

Description:

We are using `TSBasic.Process` to run external executables like the one in question (https://github.com/RobotsAndPencils/xcodes)) this particular CLI prompts users to enter an ID when running a command, using `readLine` (see here). It looks like `TSCBasic.Process` is not waiting for user input an as such the program exits with an error, similar to:

Apple ID: The operation couldn't be completed. (ExitCode(rawValue: 1))

I verified this seems isolated to `TSCBasic.Process` by running the same executable with `Foundation.Process`. The foundation process version in fact waits for user input and the application works as intended.

Im not exactly sure what could be happening here to cause this issue but judging by how many applications use `readLine` to process input this is bug that is blocking us from continuing work.

@typesanitizer
Copy link

@swift-ci create

@abertelrud
Copy link
Contributor

I would expect that if a stdin is passed (even empty), then it would be written and the input pipe closed and you'd see what you see here. But if no stdin is passed (the default), then stdin would be kept open and connected to whatever pty the parent had. So this sounds like a problem in TSCBasic.Process.

I supposed the problem is that 9 times out to 10, if you're invoking some tool like a compiler or linker or whatnot or even Git, you really don't want it to wait forever on input but rather to fail, so I would expect that usually you'd want to pass an empty stdin. So maybe this should be a more specific option than whether or not to pass stdin.

Either way, I think this type predates Foundation, and in general we probably want to move away from TSCBasic.Process in favor of Foundation.Process.

@swift-ci
Copy link
Contributor Author

Comment by Luis Padron (JIRA)

@abertelrud Thank you for your speedy reply here!

We aren't using stdin at all in the app so I think your assessment here is correct that this is some issue in TSBasic.Process.

We'll take your advice and look to migrate from TSCBasic to Foundation for this work. Just wanted to open this to ensure it gets tracked somewhere for any future users.

Thanks again for your insight!

@swift-ci
Copy link
Contributor Author

Comment by Luis Padron (JIRA)

@abertelrud Following back up here, while migrating to `Foundation.Process` I seem to have hit a roadblock in that handling interactive programs with `Process` seems to be more complicated than I previously imagined.

I'm not sure the best avenue for getting these questions answered but since I'm unfortunately stuck (and have been since I reported this issue) I'm not sure where else to go. The existing documentation for this hasn't helped me solve the problem, so I'm at this point where I can continue using the `TSCBasic.Process` and look for a bug fix to the above issue or get help with migrating to `Foundation.Process`. I'm looking for help running arbitrary executables using `Foundation.Process`. I posted in the Apple Developer Forums HERE. I'd really appreciate some help here if you or someone with some experience could help out!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants