Question

I am trying to write a shell script that launches a server and then fires up a browser to view the served content

(cd app && python -m SimpleHTTPServer) &
open http://localhost:8000

Disclaimer: I'm new to bash scripting and I don't really know python.

It seems that when adding the & operator at the end of the line, the process doesn't stay alive long enough to remain functional.

What am I doing wrong?

Was it helpful?

Solution

The problem is (probably) not that the server doesn't stay alive long enough; it's that it doesn't start up fast enough. When the open command executes, the webserver hasn't started yet, so you get an error.

Try sleeping for a second or two before the open

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top