Skip to content

Process.run() fails to execute command completely #4803

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

Open
CrazyFanFan opened this issue Jul 26, 2023 · 4 comments
Open

Process.run() fails to execute command completely #4803

CrazyFanFan opened this issue Jul 26, 2023 · 4 comments

Comments

@CrazyFanFan
Copy link

Description

When using the Process.run() method to execute a command, the command fails to execute completely and the program terminates prematurely. The issue is observed when executing the following Swift code:

print("enter")
let task = try Process.run(URL(fileURLWithPath: "/usr/bin/script"), arguments: "-aq /dev/null bash -c ls".components(separatedBy: " ")) { process in
    print(process.terminationStatus)
}

task.waitUntilExit()
print("leave")

The expected behavior is that the ls command should be executed successfully and the program should print "enter", the termination status of the process, and "leave" in the console.

Steps to reproduce

  1. Copy the above Swift code into a main.swift.
  2. Call swift main.swift
  3. Observe that the program terminates prematurely after printing "enter" and the termination status of the process.

Expected behavior

The ls command should be executed successfully and the program should print "enter", the termination status of the process, and "leave" in the console.

Note:

The issue appears to be related to the use of the /usr/bin/script command with the -aq options. Removing these options or using a different command appears to resolve the issue.

Environment

  • Swift compiler version info

swift-driver version: 1.85 Apple Swift version 5.9 (swiftlang-5.9.0.120.7 clang-1500.0.34.3)
Target: arm64-apple-macosx14.0

  • Xcode version info

Build version 15A5195m

  • Deployment target:

14.0 Beta (23A5286i)

@weissi
Copy link
Contributor

weissi commented Jul 31, 2023

Yeah, on Linux, Foundation.Process detects if the child process is running incorrectly. I can't promise but I think it's entirely possible that this bug here is caused by the same underlying issue that causes #4795

@CrazyFanFan
Copy link
Author

@weissi Thank you very much for your response. I encountered an issue while using macOS, but I believe #4795 is of reference value to this issue, and I am still exploring it. Additionally, I think this issue may have been raised in the wrong repo, but since I do not have master permissions, I am unable to transfer the issue. Would you be able to help me transfer the issue to https://github.com/apple/swift-foundation? Thank you very much!

@weissi
Copy link
Contributor

weissi commented Aug 3, 2023

@CrazyFanFan Did you use swift-foundation as a package or did you use Foundation.Process from the Apple SDK? Assuming it was the Apple SDK, the right place to report bugs is https://feedbackassistant.apple.com

@CrazyFanFan
Copy link
Author

@CrazyFanFan Did you use swift-foundation as a package or did you use Foundation.Process from the Apple SDK? Assuming it was the Apple SDK, the right place to report bugs is https://feedbackassistant.apple.com

Yes, I'm using Foundation.Process, and I've already submitted an FBA (Feedback and Bug Report): FB12842531.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants