Created
July 22, 2020 14:42
-
-
Save swinton/604cbaff60777b3cb8ee619184bd5cfc to your computer and use it in GitHub Desktop.
Run a local web server with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# enable job control | |
set -m | |
port="${1:-8000}"; | |
# start server, in background | |
python -m http.server $port & | |
# get pid | |
echo "PID: $( pidof python )" | |
# wait for server to come up | |
while ! nc -z localhost $port; do sleep 0.1; done; | |
# open web page | |
open http://localhost:$port | |
# bring to foreground | |
fg %1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment