TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Turn any application that uses stdin/stdout into a WebSocket server

311 点作者 adito超过 11 年前

12 条评论

xxchan超过 11 年前
Amazing how the old is new again. Welcome back, CGI! I hope everyone's aware that this is just a toy and should never be used to do any real work, because most command line tools were never written to be exposed to the internet at large.
评论 #6879873 未加载
评论 #6881262 未加载
评论 #6879795 未加载
评论 #6879735 未加载
评论 #6879769 未加载
评论 #6881046 未加载
joewalnes超过 11 年前
Author here.<p>If you use this on top of programs like bash, well ermm, you get what you deserve ;).<p>Here&#x27;s an example of how I used websocketd to create a little dashboard for monitoring Linux CPU&#x2F;memory&#x2F;IO stats. It basically uses websocketd to stream the output of vmstat to a web-page that plots the numbers: <a href="https://github.com/joewalnes/web-vmstats" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;joewalnes&#x2F;web-vmstats</a><p>Other useful examples: tailing log files, executing long running job and monitoring output, or interactive querying of datasets that require a long running &#x27;cursor&#x27;.<p>This is not for everyone or everything. Remember that like CGI, a process is forked for each connection so it&#x27;s not the kind of thing if you want to handle a million concurrent connections on a single server.<p>However for dashboards, admin tools, quick mashups, visualizations, etc - it&#x27;s a pretty handy tool.
评论 #6882446 未加载
评论 #6882663 未加载
tlrobinson超过 11 年前
Basically the same thing in Node.coffee, just because:<p><pre><code> { Server } = require &#x27;ws&#x27; { spawn } = require &#x27;child_process&#x27; command = process.argv[2] args = process.argv[3..] wss = new Server port: 8080 wss.on &#x27;connection&#x27;, (ws) -&gt; ps = spawn command, args ps.stdout.on &#x27;data&#x27;, (data) -&gt; ws.send data.toString() ws.on &#x27;message&#x27;, (data) -&gt; ps.stdin.write data.toString() ws.on &#x27;close&#x27;, -&gt; ps.kill() ps.on &#x27;close&#x27;, -&gt; ws.close() </code></pre> (Needs a bit more error handling)
评论 #6881344 未加载
评论 #6880922 未加载
评论 #6880065 未加载
评论 #6881038 未加载
gren超过 11 年前
<p><pre><code> websocketd --port=8080 bash </code></pre> Then in the browser console:<p><pre><code> ws.send(&quot;ls&quot;) </code></pre> I just ported bash to the web :)
评论 #6879989 未加载
评论 #6880328 未加载
评论 #6880483 未加载
评论 #6880241 未加载
babby超过 11 年前
For some stupid reason I hadn&#x27;t considered that logging stdin&#x2F;out&#x2F;err to a web interface for my node.js web apps via websockets. To think, I made a browser-side web IRC interface, and didn&#x27;t consider this. It would be so useful for my clients, who don&#x27;t know how, or find it too archaic to ssh in.<p>To just open up the admin area and see what&#x27;s going on, provided they&#x27;re indeed full-permission admins. Then, to actually send input from said interface, that could make ssh&#x27;ing into the server something one need not do often beyond initially setting up the app.<p>Thanks for the idea. Assuming we&#x27;re not running as root, and the admin side of things is secure, am I not considering any critical pitfalls of this approach? Also, any frameworky cmsy thingers that already do this? Is this new, am I a unique snowflake?
评论 #6880418 未加载
phaed超过 11 年前
This is beautiful. I can think of a dozen use cases for this right now for one of my pet projects.
评论 #6879761 未加载
hepek超过 11 年前
isn&#x27;t this reimplementing netcat -e command?<p><a href="http://linux.die.net/man/1/ncat" rel="nofollow">http:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;ncat</a>
评论 #6880026 未加载
评论 #6881518 未加载
minikomi超过 11 年前
Awesome.. I use the same kind of thing to monitor adb output sometimes:<p><a href="https://github.com/minikomi/pipesock" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;minikomi&#x2F;pipesock</a><p>also in go.<p>Edit: Doesn&#x27;t do any receiving, only pipes to a socket what it gets.
评论 #6880044 未加载
ykumar6超过 11 年前
Here is a live version <a href="http://runnable.com/UqkIJXqriJwGAATm/basic-count-example-for-shell-bash-and-websocketd#" rel="nofollow">http:&#x2F;&#x2F;runnable.com&#x2F;UqkIJXqriJwGAATm&#x2F;basic-count-example-for...</a>
eddywebs超过 11 年前
If the shells script takes input parameters can we pass that and eventually turn it into some kind of web service ?
评论 #6884979 未加载
评论 #6884502 未加载
schrodinger超过 11 年前
anyone getting an HTTPS warning? It&#x27;s telling me that github.com cert was signed by an untrusted issuer...
评论 #6879772 未加载
评论 #6879775 未加载
评论 #6879771 未加载
评论 #6879763 未加载
guard-of-terra超过 11 年前
Is this just xinetd for the ignorant?
评论 #6880443 未加载