简体   繁体   English

从 ReactJS 应用程序调用 CMD 命令行

[英]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.

相关问题 如何从 CMD 命令行启动 Node.js 应用程序,从另一个.Net core 3.0 应用程序调用它? - How to start a Node.js application from the CMD command line, calling it from another .Net core 3.0 application? 从已经运行的Electron Application获取命令行参数? - Get command line arguments from Electron Application that is already running? 从 ReactJS 应用程序解析 JSON - Parsing JSON from ReactJS application 从条件变量调用函数-ReactJS - Calling a function from a conditional variable - ReactJS ReactJS。 从外部变量调用函数 - ReactJS. calling a function from an outside variable 如何从CMD dir命令中删除每行的前30个字符,并在javascript中为每个脚本执行脚本写操作? - How do I remove the first 30 charicters in each line from a CMD dir command, and execute a script write for each in javascript? 从Reactjs中的函数内部调用组件函数 - Calling a component function from within a function in Reactjs 从 hta 批处理文件运行 CMD 命令? - Run CMD command from hta batch file? 使用exec()在cmd行中的电子js上执行命令'ADB设备' - Executing command 'ADB devices' on electron js in cmd line using exec() 从命令行调用nsIX509CertDB.nsIX509CertDB时失败 - Failure while calling nsIX509CertDB.nsIX509CertDB from command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM