admin管理员组文章数量:1415420
I have a React Application and I'm looking to run a CMD Command-Line function from a button click. What is the best way of doing this?
I am able to run the cmd mand 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. Should I be looking to set up a python server to host the python script?
Alternatively, I have been looking at Node.js would that be a better way of running this python script and ultimately connect to cmd?
I have a React Application and I'm looking to run a CMD Command-Line function from a button click. What is the best way of doing this?
I am able to run the cmd mand 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. Should I be looking to set up a python server to host the python script?
Alternatively, I have been looking at Node.js would that be a better way of running this python script and ultimately connect to cmd?
Share Improve this question edited Mar 11, 2020 at 22:13 Richard Thomas asked Mar 1, 2020 at 17:23 Richard ThomasRichard Thomas 311 silver badge3 bronze badges 3- You need to do it server-side (python, node, java..). You create your function on the server and use a rest api call to trigger it from front end (react). – Džan Operta Commented Mar 1, 2020 at 17:33
- So load the python script onto a localhost port and then call cmd from there? – Richard Thomas Commented Mar 1, 2020 at 17:41
- 2 You can run a lite python webserver with for instance Flask. You set the port on which you want to run it and create an endpoint which runs your script. For example Flask runs on localhost:8080 and your endpoint is ‘/cmd-function’. Then on frontend you execute a http get request to url localhost:8080/cmd-function and your function will be executed – Džan Operta Commented Mar 1, 2020 at 17:48
3 Answers
Reset to default 2You need to configure a server side and use the child-process module
import * as child from 'child_process';
then in your function use :
child.exec("your mand line")
React is working in the browser so it's impossible to directly access mand line.
You just need to use the child-process module
import * as child from 'child_process';
then in your function use :
child.exec("your mand line")
本文标签: javascriptCalling CMD command line from ReactJS applicationStack Overflow
版权声明:本文标题:javascript - Calling CMD command line from ReactJS application - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745217257a2648230.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论