{"id":39874515,"url":"https://github.com/liyu1981/zcmd.zig","last_synced_at":"2026-01-18T14:22:36.011Z","repository":{"id":217096650,"uuid":"743077870","full_name":"liyu1981/zcmd.zig","owner":"liyu1981","description":"zcmd is a single file lib to replace zig's std.childProcess.run with the ability of running pipeline like bash..","archived":false,"fork":false,"pushed_at":"2024-04-24T01:52:59.000Z","size":10022,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-24T03:29:28.625Z","etag":null,"topics":["zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/liyu1981.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}},"created_at":"2024-01-14T08:57:24.000Z","updated_at":"2024-04-24T01:53:02.000Z","dependencies_parsed_at":"2024-01-18T04:33:40.002Z","dependency_job_id":"bd831a29-2f04-46b9-be1b-d76c8587f945","html_url":"https://github.com/liyu1981/zcmd.zig","commit_stats":null,"previous_names":["liyu1981/zcmd.zig"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/liyu1981/zcmd.zig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fzcmd.zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fzcmd.zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fzcmd.zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fzcmd.zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liyu1981","download_url":"https://codeload.github.com/liyu1981/zcmd.zig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fzcmd.zig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28537529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T13:04:05.990Z","status":"ssl_error","status_checked_at":"2026-01-18T13:01:44.092Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["zig","zig-package"],"created_at":"2026-01-18T14:22:35.932Z","updated_at":"2026-01-18T14:22:35.999Z","avatar_url":"https://github.com/liyu1981.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zcmd.zig\n\n`zcmd` is a single file lib (`zcmd.zig`) to replace zig's `std.childProcess.run`. It has almost identical API like `std.childProcess.run`, but with the ability of running pipeline like `bash`.\n\nExample like execution of single command (replacement of zig's `std.childProcess.run`)\n\n```zig\nconst result = try Zcmd.run(.{\n    .allocator = allocator,\n    .commands = \u0026[_][]const []const u8{\n        \u0026.{ \"uname\", \"-a\" },\n    },\n});\n```\n\nthe differences to `std.childProcess.run` is it will take `commands` instead of single `command`.\n\nIt can run a `bash` like pipeline like follows (_to recursively find and list the latest modified files in a directory with subdirectories and times_)\n\n```zig\nconst result = try Zcmd.run(.{\n    .allocator = allocator,\n    .commands = \u0026[_][]const []const u8{\n        \u0026.{ \"find\", \".\", \"-type\", \"f\", \"-exec\", \"stat\", \"-f\", \"'%m %N'\", \"{}\", \";\" },\n        \u0026.{ \"sort\", \"-nr\" },\n        \u0026.{ \"head\", \"-1\" },\n    },\n});\n```\n\nIt can also accept an input from outside as stdin to command or command pipeline, like follows\n\n```zig\nconst f = try std.fs.cwd().openFile(\"tests/big_input.txt\", .{});\ndefer f.close();\nconst content = try f.readToEndAlloc(allocator, MAX_OUTPUT);\ndefer allocator.free(content);\nconst result = try Zcmd.run(.{\n    .allocator = allocator,\n    .commands = \u0026[_][]const []const u8{\n        \u0026.{\"cat\"},\n        \u0026.{ \"wc\", \"-lw\" },\n    },\n    .stdin_input = content,\n});\n```\n\nWhen there is something failed inside pipeline, we will report back `stdout` and `stderr` just like `bash`, like below example\n\n```zig\nconst result = try Zcmd.run(.{\n    .allocator = allocator,\n    .commands = \u0026[_][]const []const u8{\n        \u0026.{ \"find\", \"nonexist\" },\n        \u0026.{ \"wc\", \"-lw\" },\n    },\n});\ndefer result.deinit();\ntry testing.expectEqualSlices(\n    u8,\n    result.stdout.?,\n    \"       0       0\\n\",\n);\ntry testing.expectEqualSlices(\n    u8,\n    result.stderr.?,\n    \"find: nonexist: No such file or directory\\n\",\n);\n```\n\nPlease check [example/zcmd_app](https://github.com/liyu1981/zcmd.zig/tree/main/example/zcmd_app) for an example on how to use `zcmd.zig`.\n\n### use `zcmd.zig` in `build.zig`\n\nOriginally `zcmd.zig` is functions I wrote in `build.zig` to auto generating files with commands, so it is important that can use this in `build.zig`. So `zcmd.zig` exposed itself for `build.zig` too.\n\nTo use that we will need to normally introduce `zcmd.zig` to `build.zig.zon` (see Usage below). Then in your `build.zig`, do following to use it\n\n```zig\n// when import in build.zig, the zcmd is exposed in nested const zcmd\nconst zcmd = @import(\"zcmd\").zcmd;\n// then next can use zcmd.run as above\n```\n\nPlease check [example/zcmd_build_app](https://github.com/liyu1981/zcmd.zig/tree/main/example/zcmd_build_app) for detail version how to use in this way.\n\n## Usage\n\n### through Zig Package Manager\n\nuse following bash in your project folder (with `build.zig.zon`)\n\n```\nzig fetch --save https://github.com/liyu1981/zcmd.zig/archive/refs/tags/v0.2.2.tar.gz\n```\n\nyou can change the version `v0.1.0` to other version if there are in [release](https://github.com/liyu1981/zcmd.zig/releases) page.\n\n### or simply just copy `zcmd.zig` file to your project\n\nIt is a single file lib with no dependencies!\n\n## Zig Docs\n\nZig docs is hosted in github pages at: [https://liyu1981.github.io/zcmd.zig/](https://liyu1981.github.io/zcmd.zig/), please go there to\nfind what apis `zcmd.zig` provides.\n\n## Coverage\n\n`zcmd.zig` is rigorously tested. Run unit tests at repo checkout root folder with `zig test src/zcmd.zig`.\n\nFor coverage test, as `kcov` is working in a way of 'debug every line and record', it can not work with `zcmd` tests. `zcmd` tests will fork many sub processes and if one of them be stopped the whole pipeline hangs. I am still in searching of what's the best method to cover.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyu1981%2Fzcmd.zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliyu1981%2Fzcmd.zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyu1981%2Fzcmd.zig/lists"}