[英]Calling CMD command line from ReactJS application
I have a React Application and I'm looking to run a CMD Command-Line function from a button click.我有一个 React 应用程序,我希望通过单击按钮运行 CMD 命令行 function。 What is the best way of doing this?
这样做的最佳方法是什么?
I am able to run the cmd command through a python script of my own however how could I run this python from React as React is hosted on localhost and security permissions limit access to cmd from there.我可以通过我自己的 python 脚本运行 cmd 命令,但是我怎么能从 React 运行这个 python,因为 React 托管在本地主机上,安全权限限制从那里访问 cmd。 Should I be looking to set up a python server to host the python script?
我是否应该设置一个 python 服务器来托管 python 脚本?
Alternatively, I have been looking at Node.js would that be a better way of running this python script and ultimately connect to cmd?或者,我一直在查看 Node.js,这会是运行此 python 脚本并最终连接到 cmd 的更好方法吗?
React 在浏览器中运行,因此无法直接访问命令行。
You just need to use the child-process module import * as child from 'child_process';
您只需要使用子进程模块
import * as child from 'child_process';
then in your function use: child.exec("your command line")
然后在您的 function 中使用:
child.exec("your command line")
You need to configure a server side and use the child-process module import * as child from 'child_process';
您需要配置服务器端并使用子进程模块
import * as child from 'child_process';
then in your function use : child.exec("your command line")
然后在你的函数中使用:
child.exec("your command line")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.