简体   繁体   English

如何使用 javascript 在 HTML 中运行命令行?

[英]How to run a command line in HTML using javascript?

First of all, I have nearly zero experience with HTML and java, so a simple answer will be appreciated!首先,我对 HTML 和 Java 的经验几乎为零,因此将不胜感激!

I'm working on a WSN project using a telosb mote running TinyOS and Xubuntu, what I have to do is set up a web server that can communicate with my mote, and the only way I know of doing this is with command lines, using "java net.tinyos.tools.Send X" where X is my input from my web server.我正在使用运行 TinyOS 和 Xubuntu 的 telosb 节点处理 WSN 项目,我要做的是设置一个可以与我的节点通信的 Web 服务器,我知道的唯一方法是使用命令行,使用“java net.tinyos.tools.Send X”,其中 X 是我从我的网络服务器输入的。

So on my web server, have a form where i can input a number to send to my mote, and when submitting the number a function runs the command java net.tinyos.tools.Send X .所以在我的网络服务器上,有一个表格,我可以输入一个数字发送到我的节点,当提交数字时,一个函数运行命令java net.tinyos.tools.Send X

Is this possible?这可能吗?

I have read previous answered questions but please note that I know nothing about java as I work with electronics, so I pray for answers that a beginner like me will understand.我已经阅读了以前回答过的问题,但请注意,我在从事电子工作时对 Java 一无所知,所以我祈祷像我这样的初学者能够理解的答案。 Thank you very much!非常感谢!

Yes you can run system commands using a web server.是的,您可以使用 Web 服务器运行系统命令。 Simply send the value from browser to your server.只需将值从浏览器发送到您的服务器。 And when the server receives the value you can execute the desired system command.当服务器收到该值时,您可以执行所需的系统命令。

For example, If your server is in python (eg Flask), look for os.system in python os module.例如,如果您的服务器是 Python(例如 Flask),请在 python os模块中查找os.system https://docs.python.org/3/library/os.html https://docs.python.org/3/library/os.html

if your server is in nodejs (eg Express) look for child_process.exec in child_process module to run system commands.如果您的服务器在 nodejs(例如 Express)中, child_process.execchild_process模块中查找 child_process.exec以运行系统命令。 https://nodejs.org/api/child_process.html https://nodejs.org/api/child_process.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM