Home > Enterprise >  Batch File to open Chrome and launch Python Dash App
Batch File to open Chrome and launch Python Dash App

Time:04-19

I have a Dash App I'm running locally on a few machines through waitress, and I want it to open by clicking a simple batch file. I would lke to improve two things: that it'll open chrome only after the Flask server is running already, and if possible that it won't display the cmd window at all.

Currently I have this:

@echo off
start chrome http://127.0.0.1:8050 
python route "script route"
exit

It works but it opens chrome first and I have to refresh a few times until the server is up. And if I put chrome under the python command It never opnes because the python command is never truly "finished" until you close the cmd window and the app stops (which is why I think it won't be possible to hide the cmd window completely)

I'll appreciate any help you guys can give me.

CodePudding user response:

If you have curl on your device:

@echo off
:Test
Curl http://127.0.0.1:8050
If "%errorlevel%" neq "0" goto :Test
start "" "chrome.exe" "http://127.0.0.1:8050"
python route "script route"

a slightly Shorter method using conditional operators.

@echo off
:Test
Curl http://127.0.0.1:8050 && (start "" "chrome.exe" "http://127.0.0.1:8050" & python route "script route") || goto :Test

CodePudding user response:

When you can use the some countdown time before running the server

@echo off
timeout 5
start chrome http://127.0.0.1:8050 
python route "script route"
exit

And about hiding the cmd this can be achieved by using cmdow https://ritchielawrence.github.io/cmdow/

cmdow /run /hid mybat arg1 "arg 2"
  • Related