最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Calling CMD command line from ReactJS application - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 2

You 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")

发布评论

评论列表(0)

  1. 暂无评论