I want to start a web server via Python. When this succeeds, I want to open the page in the default browser (on macOS, you can do this with the open
command), and after that, I want to resume the previous script again.
This does not work:
#!/usr/bin/env bash
cd wwwroot
python3 -m http.server &
open http://0.0.0.0:8000
fg 1
I could not use jobs
, and open the URL, and after that just run the Python script. However, I don't want to reload the page of the URL. Python will continue to run, until stopped by Ctrl+C.
Perhaps, the open
command needs to have a sleep
command when Python is not ready yet...
python3 -m http.server && open http://0.0.0.0:8000
. the&&
means run whatever command is next if the first one succeeds