{"id":13496739,"url":"https://github.com/Zollerboy1/SwiftCommand","last_synced_at":"2025-03-28T19:30:57.763Z","repository":{"id":63921282,"uuid":"524435244","full_name":"Zollerboy1/SwiftCommand","owner":"Zollerboy1","description":"A wrapper around Foundation.Process, inspired by Rust's std::process::Command.","archived":false,"fork":false,"pushed_at":"2024-06-17T16:31:56.000Z","size":108,"stargazers_count":77,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-17T09:07:51.896Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/Zollerboy1/SwiftCommand","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zollerboy1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-13T15:22:32.000Z","updated_at":"2024-06-17T16:32:00.000Z","dependencies_parsed_at":"2024-04-23T15:26:59.907Z","dependency_job_id":"13caaddd-4240-4698-b3c1-36463dc21f14","html_url":"https://github.com/Zollerboy1/SwiftCommand","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.05555555555555558,"last_synced_commit":"252959d9c0dd5d6150aff83b0da490a5f2e9fe49"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zollerboy1%2FSwiftCommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zollerboy1%2FSwiftCommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zollerboy1%2FSwiftCommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zollerboy1%2FSwiftCommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zollerboy1","download_url":"https://codeload.github.com/Zollerboy1/SwiftCommand/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246088397,"owners_count":20721679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:01:58.439Z","updated_at":"2025-03-28T19:30:57.504Z","avatar_url":"https://github.com/Zollerboy1.png","language":"Swift","readme":"# SwiftCommand\n\n![Platforms: macOS/Linux/Windows\\*](https://img.shields.io/badge/Platforms-macOS%20%7C%20Linux%20%7C%20Windows%2A-F05138)\n[![Supported swift versions](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FZollerboy1%2FSwiftCommand%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/Zollerboy1/SwiftCommand)\n\n*\\*Windows support is only experimental for now.*\n\n---\n\nA wrapper around `Foundation.Process`, inspired by Rust's\n`std::process::Command`. This package makes it easy to call command line\nprograms and handle their I/O.\n\n## Installation\n\nYou can install this package using the Swift Package Manager, by including it in\nthe dependencies of your package:\n\n```swift\nlet package = Package(\n    // ...\n    dependencies: [\n        // other dependencies...\n        .package(\n            url: \"https://github.com/Zollerboy1/SwiftCommand.git\",\n            from: \"1.4.0\"\n        ),\n    ],\n    // ...\n)\n```\n\n## Usage\n\nUsing this package is very easy.\n\nBefore you start, make sure that you've imported the `SwiftCommand` module:\n\n```swift\nimport SwiftCommand\n```\n\nNow it can be used like this:\n\n```swift\nlet output = try Command.findInPath(withName: \"echo\")!\n                        .addArgument(\"Foo\")\n                        .waitForOutput()\n\nprint(output.stdout)\n// Prints 'Foo\\n'\n```\n\nThis blocks the thread until the command terminates. You can use the\n`async`/`await` API instead, if you want to do other work while waiting for the\ncommand to terminate:\n\n```swift\nlet output = try await Command.findInPath(withName: \"echo\")!\n                              .addArgument(\"Foo\")\n                              .output\n\nprint(output.stdout)\n// Prints 'Foo\\n'\n```\n\n### Specifying command I/O\n\nSuppose that you have a file called `SomeFile.txt` that looks like this:\n\n```\nFoo\nBar\nBaz\n```\n\nYou can then set stdin and stdout of commands like this:\n\n```swift\nlet catProcess = try Command.findInPath(withName: \"cat\")!\n                            .setStdin(.read(fromFile: \"SomeFile.txt\"))\n                            .setStdout(.pipe)\n                            .spawn()\n\nlet grepProcess = try Command.findInPath(withName: \"grep\")!\n                             .addArgument(\"Ba\")\n                             .setStdin(.pipe(from: catProcess.stdout))\n                             .setStdout(.pipe)\n                             .spawn()\n\nfor try await line in grepProcess.stdout.lines {\n    print(line)\n}\n// Prints 'Bar' and 'Baz'\n\ntry catProcess.wait()\ntry grepProcess.wait()\n// Ensure the processes are terminated before exiting the parent process\n```\n\nThis is doing in Swift, what you would normally write in a terminal like this:\n\n```bash\ncat \u003c SomeFile.txt | grep Ba\n```\n\nIf you don't specify stdin, stdout, or stderr, and also don't capture the output\n(using e.g. `waitForOutput()`), then they will by default inherit the\ncorresponding handle of the parent process. E.g. the stdout of the following\nprogram is `Bar\\n`:\n\n```swift\nimport SwiftCommand\n\ntry Command.findInPath(withName: \"echo\")!\n           .addArgument(\"Bar\")\n           .wait()\n```\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FZollerboy1%2FSwiftCommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FZollerboy1%2FSwiftCommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FZollerboy1%2FSwiftCommand/lists"}