开发者

Is it possible to show interactive shell command output on a webpage without refreshing the webpage?

开发者 https://www.devze.com 2023-04-11 05:52 出处:网络
Is it possible to show interactive shell command output on a webpage without refreshing the webpage? For example, can we update a webpage with the latest snapshot of the (Linux) Top command\'s output

Is it possible to show interactive shell command output on a webpage without refreshing the webpage?

For example, can we update a webpage with the latest snapshot of the (Linux) Top command's output every 1 second without refreshing the webpage?

It will be very helpful if anyone can 开发者_运维知识库teach me how to take a text-based snapshot of the latest output of an interactive shell command.

Thanks.


Yes, you need to use an AJAX-style request to refresh the contents periodically. That's a broad subject though, so not an easy one to cover in a few minutes here!

Have a look at some of the more popular JavaScript libraries like jQuery or Mootools and you will see methods for making AJAX requests. JSON is about the easiest format to transfer data in for this type of work, since both PHP and JavaScript support it natively. Ie. you can encode your data in JSON in one line from PHP and then decode in JavaScript simply by eval'ing it.

Edit: And now I re-read your question, I've missed half the point! Not sure off-hand on the interactive shell output question. I tried this just now - the command didn't terminate unfortunately, but it did write output to test.txt.

top > test.txt

Perhaps there is a way to make it non-interactive.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号