Skip to content

Instantly share code, notes, and snippets.

@swinton
Created July 22, 2020 14:42
Show Gist options
  • Save swinton/604cbaff60777b3cb8ee619184bd5cfc to your computer and use it in GitHub Desktop.
Save swinton/604cbaff60777b3cb8ee619184bd5cfc to your computer and use it in GitHub Desktop.
Run a local web server with Python
#!/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