{"id":18448812,"url":"https://github.com/synrc/exe","last_synced_at":"2025-04-08T01:32:41.325Z","repository":{"id":16890317,"uuid":"19651006","full_name":"synrc/exe","owner":"synrc","description":"🖥️ EXE: Shell Exec","archived":false,"fork":false,"pushed_at":"2023-11-30T02:39:46.000Z","size":67,"stargazers_count":36,"open_issues_count":2,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T05:33:39.223Z","etag":null,"topics":["exec","shell"],"latest_commit_sha":null,"homepage":"https://exe.n2o.dev","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/synrc.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}},"created_at":"2014-05-10T20:13:37.000Z","updated_at":"2023-08-11T08:01:39.000Z","dependencies_parsed_at":"2023-12-10T20:48:35.623Z","dependency_job_id":null,"html_url":"https://github.com/synrc/exe","commit_stats":{"total_commits":64,"total_committers":6,"mean_commits":"10.666666666666666","dds":0.109375,"last_synced_commit":"fd9955dbfd4b3fb8e0976b005bbcfb82880630c4"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Fexe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Fexe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Fexe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synrc%2Fexe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/synrc","download_url":"https://codeload.github.com/synrc/exe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223126124,"owners_count":17091532,"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":["exec","shell"],"created_at":"2024-11-06T07:17:18.585Z","updated_at":"2024-11-06T07:17:19.196Z","avatar_url":"https://github.com/synrc.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sh: your unix gateway\n\n[![Hex pm](http://img.shields.io/hexpm/v/exe.svg?style=flat)](https://hex.pm/packages/exe)\n\nFamily of functions and ports to interact with system shell, paths and external programs.\n\n## Avoid `os:cmd/1` on user input!\n\n```erlang\n\u003e Email = \"proger+/\u0026reboot%23@hackndev.com\". % valid email!\n\u003e os:cmd([\"mkdir -p \", Email]).\n% path clobbering and a reboot may happen here!\n```\n\n## Examples\n\n### Onliners\n\n```erlang\n\u003e sh:oneliner([\"touch\", filename:join(\"/tmp/\", Path)]).\n{done,0,\u003c\u003c\u003e\u003e}\n\n\u003e sh:oneliner(\"uname -mnprs\").\n{done,0,\u003c\u003c\"Darwin mac 18.2.0 x86_64 i386\"\u003e\u003e}\n\n\u003e sh:oneliner(\"git describe --always\").\n{done,128,\u003c\u003c\"fatal: Not a valid object name HEAD\"\u003e\u003e}\n\n\u003e sh:oneliner(\"git describe --always\", \"/tank/proger/vxz/otp\").\n{done,0,\u003c\u003c\"OTP_R16B01\"\u003e\u003e}\n```\n\n### Escaping\n\n```erlang\n\u003e Path = sh_path:escape(\"email+=/subdir@example.com\").\n\"email+=%2Fsubdir@example.com\"\n```\n\n### Run\n\n```erlang\n\u003e sh:run([\"git\", \"clone\", \"https://github.com/proger/darwinkit.git\"], binary, \"/tmp\").\n{done,0,\u003c\u003c\"Cloning into 'darwinkit'...\\n\"\u003e\u003e}\n\n\u003e UserUrl = \"https://github.com/proger/darwinkit.git\".\n\"https://github.com/proger/darwinkit.git\"\n\u003e sh:run([\"git\", \"clone\", UserUrl], binary, \"/tmp\").\n{done,128,\n      \u003c\u003c\"fatal: destination path 'darwinkit' already exists and is not an empty directory.\\n\"\u003e\u003e}\n\n\u003e sh:run([\"ifconfig\"], \"/tmp/output.log\", \"/tank/proger/vxz/otp\").\n{done,0,\"/tmp/output.log\"}\n\n% cat /tmp/output.log\n\u003e\u003e\u003e {{2013,8,28},{8,39,14}} /sbin/ifconfig\nlo0: flags=8049\u003cUP,LOOPBACK,RUNNING,MULTICAST\u003e mtu 16384\n\toptions=3\u003cRXCSUM,TXCSUM\u003e\n\tinet6 fe80::1%lo0 prefixlen 64 scopeid 0x1\n\tinet 127.0.0.1 netmask 0xff000000\n\tinet6 ::1 prefixlen 128\ngif0: flags=8010\u003cPOINTOPOINT,MULTICAST\u003e mtu 1280\nstf0: flags=0\u003c\u003e mtu 1280\nen0: flags=8863\u003cUP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST\u003e mtu 1500\n\tether 7c:d1:c3:e9:24:65\n\tinet6 fe80::7ed1:c3ff:fee9:2465%en0 prefixlen 64 scopeid 0x4\n\tinet 192.168.63.163 netmask 0xfffffc00 broadcast 192.168.63.255\n\tmedia: autoselect\n\tstatus: active\np2p0: flags=8843\u003cUP,BROADCAST,RUNNING,SIMPLEX,MULTICAST\u003e mtu 2304\n\tether 0e:d1:c3:e9:24:65\n\tmedia: autoselect\n\tstatus: inactive\n\u003e\u003e\u003e {{2013,8,28},{8,39,14}} exit status: 0\n```\n\n## fdlink: make sure your ports exit when you exit\n\nConsider a case of spawning a port that does not actually\nread its standard input (e.g. `socat` that bridges `AF_UNIX` with `AF_INET`):\n\n```shell\n# pstree -A -a $(pgrep beam.smp)\nbeam.smp -- -root /usr/lib/erlang -progname erl -- -home /root -- -pa ebin -config sys.config\n  |-socat tcp-listen:32133,reuseaddr,bind=127.0.0.1 unix-connect:/var/run/docker.sock\n  `-16*[{beam.smp}]\n```\n\nIf you terminate the node, beam will close the port but the process\nwill still remain alive (thus, it will leak). To mitigate this issue,\nyou can use `fdlink` that tracks `stdin` availability for you:\n\n### Usage\n\n```erlang\n\u003e Fdlink = sh:fdlink_executable().\n\u003e erlang:open_port({spawn_executable, Fdlink},\n         [stream, exit_status, {args, [\"/usr/bin/socat\"|Args]}).\n```\n\n`fdlink` will also close the standard input of its child process.\n\n## Credits\n\n* Vladimir Kirillov\n\nOM A HUM\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynrc%2Fexe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynrc%2Fexe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynrc%2Fexe/lists"}