Skip to content

Instantly share code, notes, and snippets.

@tdpreece
Created September 25, 2015 16:38
Show Gist options
  • Save tdpreece/91c6b0305cc7a151e03f to your computer and use it in GitHub Desktop.
Save tdpreece/91c6b0305cc7a151e03f to your computer and use it in GitHub Desktop.
Running a Python SimpleHTTPServer in the background and killing it when doneSimpleHTTPServer
#!/usr/bin/env bash
# Create a page in the current dir
echo "My Test Page" > test.html
# Start server
python -m SimpleHTTPServer 8000 &> /dev/null &
pid=$!
# Give server time to start up
sleep 1
# request page and print to stdout
wget -O - http://0.0.0.0:8000/test.html 2> /dev/null
# Stop server
kill "${pid}"
# Output on running script:
# My Test Page
@jfach
Copy link

jfach commented Nov 22, 2016

Nice... thanks.

@c4cat
Copy link

c4cat commented Apr 1, 2017

thx!

@jkraszewski
Copy link

Great Example

@saymoncoppi
Copy link

Hey Guys! Great tip... I made a similar to use CGI:
python -m CGIHTTPServer 8000
(put the files under the /cgi-bin folder and apply chmod a+x to those files)

@greenmind-sec
Copy link

Very nice :D
Using Python3: python3 -m http.server --cgi 8009 &> /dev/null &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment