Skip to content

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

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

Closed
CrazyFanFan opened this issue Jul 25, 2023 · 4 comments
Closed

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

CrazyFanFan opened this issue Jul 25, 2023 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. cloned Resolution: Was resubmitted in the appropriate repository rather than transferred

Comments

@CrazyFanFan
Copy link
Contributor

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)

@CrazyFanFan CrazyFanFan added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jul 25, 2023
@AnthonyLatsis AnthonyLatsis added transfer candidate The issue may belong in another repository and removed triage needed This issue needs more specific labels labels Jul 26, 2023
@AnthonyLatsis
Copy link
Collaborator

I think this should be transferred to swift-foundation.

@CrazyFanFan
Copy link
Contributor Author

@AnthonyLatsis Thank you for your suggestion. I have moved this issue to swiftlang/swift-corelibs-foundation#4803.

@AnthonyLatsis AnthonyLatsis added cloned Resolution: Was resubmitted in the appropriate repository rather than transferred and removed transfer candidate The issue may belong in another repository labels Jul 26, 2023
@AnthonyLatsis
Copy link
Collaborator

swift-corelibs-foundation is the Foundation for non-Apple platforms, but I guess it’s fine.

Please try transferring the issue next time (or ask us) instead of cloning. This way we can avoid polluting the issue database.

@AnthonyLatsis AnthonyLatsis closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2023
@CrazyFanFan
Copy link
Contributor Author

swift-corelibs-foundation is the Foundation for non-Apple platforms, but I guess it’s fine.

Please try transferring the issue next time (or ask us) instead of cloning. This way we can avoid polluting the issue database.

I learned something new today, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. cloned Resolution: Was resubmitted in the appropriate repository rather than transferred
Projects
None yet
Development

No branches or pull requests

2 participants