[英]How to write a starter script to start my backend and frontend?
I running python flask as my backend and react as my frontend. 我将python flask作为后端运行,并作为前端进行响应。 Every time I start my app, I have to run
export FLASK_APP=app
and then flask start
in terminal 1 and npm start
in terminal 2. How do I write a single script that starts both processes? 每次启动我的应用程序时,都必须运行
export FLASK_APP=app
,然后在终端1 flask start
在终端2 flask start
npm start
。如何编写一个启动两个进程的脚本? Here is my attempt: 这是我的尝试:
#!/bin/bash
export FLASK_APP=microblog.py
flask run > /dev/null
npm start --prefix ~/app
Try this: 尝试这个:
#!/bin/bash
export FLASK_APP=microblog.py
flask run > /dev/null & pids=$!
npm start --prefix ~/app & pids+=" $!"
trap "kill $pids" SIGTERM SIGINT
wait $pids
This script starts both flask and npm in background, and stores their PIDs. 该脚本在后台启动flask和npm,并存储它们的PID。 After that, we set up a trap - in case you hit
CTRL - C
, both programs will get killed. 之后,我们设置了一个陷阱-如果您按
CTRL - C
,则两个程序都将被杀死。 The wait
line will block until both the flask and npm process has finished - so you can easily terminate both with CTRL-C
. wait
行将阻塞,直到flask和npm过程都完成为止-因此您可以使用CTRL-C
轻松终止两者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.