{"id":24758836,"url":"https://github.com/wesleych3n/process-cpp","last_synced_at":"2025-03-23T10:16:46.694Z","repository":{"id":256033593,"uuid":"853272898","full_name":"WesleyCh3n/process-cpp","owner":"WesleyCh3n","description":"A rust-like C++ API to easily create process, pipe stdio, etc on win/unix","archived":false,"fork":false,"pushed_at":"2024-09-20T07:56:37.000Z","size":103,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T10:16:41.461Z","etag":null,"topics":["cmake","cpp","pipes","rust","stdio","subprocess","unix","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WesleyCh3n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-09-06T10:28:33.000Z","updated_at":"2025-01-07T14:30:16.000Z","dependencies_parsed_at":"2025-01-28T16:41:34.224Z","dependency_job_id":"3b79c0b8-895e-4992-a5b2-c5cf84dd678f","html_url":"https://github.com/WesleyCh3n/process-cpp","commit_stats":null,"previous_names":["wesleych3n/std-process","wesleych3n/process-cpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyCh3n%2Fprocess-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyCh3n%2Fprocess-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyCh3n%2Fprocess-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesleyCh3n%2Fprocess-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WesleyCh3n","download_url":"https://codeload.github.com/WesleyCh3n/process-cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245084608,"owners_count":20558251,"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":["cmake","cpp","pipes","rust","stdio","subprocess","unix","windows"],"created_at":"2025-01-28T16:39:24.430Z","updated_at":"2025-03-23T10:16:46.685Z","avatar_url":"https://github.com/WesleyCh3n.png","language":"C++","readme":"# Process cpp\n\nA c++ implementation similar to Rust's [std::process](https://doc.rust-lang.org/std/process/index.html).\n\n## Quick Start\n\nFollowing quick start is for linux and mac\n\n1. get the library to your directory\n```sh\nwget https://github.com/WesleyCh3n/process-cpp/raw/refs/heads/main/src/process.hpp\nwget https://github.com/WesleyCh3n/process-cpp/raw/refs/heads/main/src/unix.cpp\n```\n\n2. create a new file named `example.cpp` with following:\n\n```cpp\n#include \"process.hpp\"\n\n#include \u003ciomanip\u003e\n#include \u003ciostream\u003e\n\nint main(int argc, char *argv[]) {\n  auto output =\n      process::Command(\"sh\").arg(\"-c\").arg(\"echo hello world\").output();\n  std::cout \u003c\u003c std::boolalpha \u003c\u003c output.status.success() \u003c\u003c '\\n';\n  std::cout \u003c\u003c std::quoted(output.std_out) \u003c\u003c '\\n';\n  std::cout \u003c\u003c std::quoted(output.std_err) \u003c\u003c '\\n';\n}\n```\n\n3. Compile\n\n```sh\nc++ -std=c++20 -o example example.cpp unix.cpp\n```\n\n4. `./example`\n\n```sh\ntrue\n\"hello world\n\"\n\"\"\n```\n\n## Usage\n\nFor more detail, check [examples](https://github.com/WesleyCh3n/std-process/tree/main/example) and [process.hpp](https://github.com/WesleyCh3n/std-process/blob/main/src/process.hpp).\n\n```cpp\n#include \"process.hpp\"\n\n#include \u003ciomanip\u003e\n#include \u003ciostream\u003e\n\nint main() {\n    {\n        // windows. wait for output\n        Output output = Command(\"cmd\").args({\"/c\", \"echo hello world\"}).output();\n        std::cout \u003c\u003c std::quoted(output.std_out) \u003c\u003c '\\n';\n        std::cout \u003c\u003c std::quoted(output.std_err) \u003c\u003c '\\n';\n    }\n    {\n        // unix. get child handle and wait for output\n        Child child = Command(\"sh\")\n            .arg(\"-c\")\n            .arg(\"echo hello world\")\n            .std_out(Stdio::pipe())\n            .std_err(Stdio::pipe())\n            .spawn();\n        Output output = child.wait_with_output();\n\n        std::cout \u003c\u003c std::quoted(output.std_out) \u003c\u003c '\\n';\n        std::cout \u003c\u003c std::quoted(output.std_err) \u003c\u003c '\\n';\n    }\n    {\n        // write to process stdin\n        std::string app = \"some_app_need_stdin\";\n        auto child = Command(app).std_in(Stdio::pipe()).spawn();\n\n        std::vector\u003cstd::string\u003e strs{\"hello\\n\", \"from\\n\", \"parent\\n\"};\n        for (auto \u0026str : strs) {\n            child.io_stdin-\u003ewrite(std::as_bytes(std::span{str}));\n        }\n        ExitStatus status = child.wait();\n    }\n    {\n        // pipe process one stdout to process 2 stdin\n        // p1.stdout -\u003e p2.stdin\n        auto child1 = Command(app1).args(args1).std_out(Stdio::pipe()).spawn();\n        auto child2 = Command(app2)\n            .args(args2)\n            .std_in(Stdio::from(std::move(*child1.io_stdout)))\n            .spawn();\n        ExitStatus status = child2.wait();\n    }\n}\n```\n\n## Build and Install\n\n```sh\ncmake -Bbuild .\ncmake --build build -j\n```\n\nFor more CMake options, see [CMakeLists.txt](https://github.com/WesleyCh3n/std-process/blob/main/CMakeLists.txt)\n\n\n## Run Test\n\nAfter test built,\n\n```sh\nctest --output-on-failure --test-dir ./build/test/\n```\n\n## License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwesleych3n%2Fprocess-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwesleych3n%2Fprocess-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwesleych3n%2Fprocess-cpp/lists"}