{"id":13509684,"url":"https://github.com/proger/erlsh","last_synced_at":"2026-01-11T02:42:34.224Z","repository":{"id":10305341,"uuid":"12428840","full_name":"proger/erlsh","owner":"proger","description":"Erlang shell tools","archived":false,"fork":false,"pushed_at":"2022-04-17T14:58:10.000Z","size":14,"stargazers_count":61,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-01T09:35:03.639Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/proger.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}},"created_at":"2013-08-28T08:42:31.000Z","updated_at":"2023-04-10T05:06:40.000Z","dependencies_parsed_at":"2022-08-30T13:52:13.175Z","dependency_job_id":null,"html_url":"https://github.com/proger/erlsh","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proger%2Ferlsh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proger%2Ferlsh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proger%2Ferlsh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proger%2Ferlsh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/proger","download_url":"https://codeload.github.com/proger/erlsh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246324241,"owners_count":20759098,"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-08-01T02:01:11.454Z","updated_at":"2026-01-11T02:42:34.181Z","avatar_url":"https://github.com/proger.png","language":"Erlang","funding_links":[],"categories":["Utilities"],"sub_categories":[],"readme":"## erlsh\n\nFamily of functions and ports involving interacting with the system shell, paths and external programs.\n\nReason why not `os:cmd/1`:\n\n```erlang\n\u003e Email = \"hacker+/somepath\u0026reboot#@example.com\". % this is a valid email!\n\u003e os:cmd([\"mkdir -p \", Email]).\n% path clobbering and a reboot may happen here!\n```\n\nExamples with `erlsh:run/1,2,3,4`, `erlsh:oneliner/1,2`, `erlsh_path:escape/1`:\n\n```erlang\n\u003e erlsh:oneliner(\"uname -v\"). % oneliner/1,2 funs do not include newlines\n{done,0,\n      \u003c\u003c\"Darwin Kernel Version 12.4.0: Wed May  1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64\"\u003e\u003e}\n\n\u003e erlsh:oneliner(\"git describe --always\").\n{done,128,\u003c\u003c\"fatal: Not a valid object name HEAD\"\u003e\u003e}\n\n\u003e erlsh:oneliner(\"git describe --always\", \"/tank/proger/vxz/otp\").\n{done,0,\u003c\u003c\"OTP_R16B01\"\u003e\u003e}\n\n\u003e erlsh: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 erlsh: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 Path = erlsh_path:escape(\"email+=/subdir@example.com\").\n\"email+=%2Fsubdir@example.com\"\n\n\u003e erlsh:oneliner([\"touch\", filename:join(\"/tmp/\", Path)]).\n{done,0,\u003c\u003c\u003e\u003e}\n\n\u003e erlsh: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 port\n\nConsider a case of spawning a port that does not actually read its standard input (e.g. `socat` that bridges `AF_UNIX` with `AF_INET`):\n\n``` shell\n# pstree -A -a $(pgrep make)\nmake run\n  `-sh -c...\n      `-beam.smp -- -root /usr/lib/erlang -progname erl -- -home /root -- -pa ebin -config run/sys.config -eval[ok = application:\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 will still remain alive (thus, it will leak).\n\nTo mitigate this issue, you can use `fdlink` that will track `stdin` availability for you:\n\n``` shell\n# pstree -A -a $(pgrep make)\nmake run\n  `-sh -c...\n      `-beam.smp -- -root /usr/lib/erlang -progname erl -- -home /root -- -pa ebin -config run/sys.config -eval[ok = application:\n          |-fdlink /usr/bin/socat tcp-listen:32133,reuseaddr,bind=127.0.0.1 unix-connect:/var/run/docker.sock\n          |   `-socat tcp-listen:32133,reuseaddr,bind=127.0.0.1 unix-connect:/var/run/docker.sock\n          `-16*[{beam.smp}]\n```\n\nUsing `fdlink` is easy:\n\n```erlang\n\u003e Fdlink = erlsh:fdlink_executable().               % make sure your app dir is setup correctly\n\u003e Fdlink = filename:join(\"./priv\", \"fdlink\").       % in case you're running directly from erlsh root\n\n\u003e erlang:open_port({spawn_executable, Fdlink}, [stream, exit_status, {args, [\"/usr/bin/socat\"|RestOfArgs]}).\n```\n\n`fdlink` will also close the standard input of its child process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproger%2Ferlsh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproger%2Ferlsh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproger%2Ferlsh/lists"}