0

I am automating the process of starting IIS Express then starting ngrok and opening a web page automatically in order to browse a site. Unfortunately I am stuck at the final hurdle because once ngrok starts the final line of the batch file to open the page will not run until the ngrok process ends which is obviously not very helpful.

Example:

ngrok http -subdomain=mysubdomain 192.168.0.2:%port%

:: Pause for 3 seconds as IIS Express takes a moment to start
timeout /t 3

:: launch the browser pointing to this location
start /B "" http://mysubdomain.ngrok.io

If I alter the line that starts ngrok (as below) everything runs as I want but I lose the ability to interact with ngrok once the page has opened:

start /B "" ngrok http -subdomain=mysubdomain 192.168.0.2:%port%

Can I achieve what I want in just a batch file and if so what am I missing? I really want to keep this self contained and portable in a single batch file if I can.

ProNotion
  • 3,662
  • 3
  • 21
  • 30

1 Answers1

1

Preemptively start the countdown and subsequent launch of the browser.

  • In the same console:

    start /b "" cmd /c timeout /t 3 ^& start /B "" http://mysubdomain.ngrok.io
    ngrok http -subdomain=mysubdomain 192.168.0.2:%port%
    
  • Or in a separate minimized console window:

    start /min "" cmd /c timeout /t 3 ^& start /B "" http://mysubdomain.ngrok.io
    ngrok http -subdomain=mysubdomain 192.168.0.2:%port%
    
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • That's great, I didn't realise that was possible without also blocking the subsequent processes. – ProNotion Aug 12 '15 at 20:42
  • OK so I've now tried this and ngrok starts up and the web page opens so all is good there but in the window where ngrok is running I still cannot interact with the process? Normally if I run ngrok directly I can at least CTRL+C to end the process but in this scenario I can't. – ProNotion Aug 13 '15 at 06:55
  • Sorry I just edited my comment to state that CTRL+C is what I am unable to do to kill the process. – ProNotion Aug 13 '15 at 06:59
  • When running ngrok from the command line it says in the first line "(CTRL+C to Quit) which works if I just run ```ngrok http -subdomain=mysubdomain 192.168.0.2:8567``` and in order to run ```ngrok --stop``` I would need a cmd prompt. – ProNotion Aug 13 '15 at 07:03
  • Huh, in my example ngrok is executed just the same as from a command prompt. Maybe there's something else in your batch file? – wOxxOm Aug 13 '15 at 07:07
  • I start IIS Express in a new window before running this using the following command ```start "IIS Express :%port%" cmd /C " "%ProgramFiles%\IIS Express\iisexpress.exe" /site:mysubdomain /systray:true "```. I am going to isolate this piece of code we are discussing and try it independently. – ProNotion Aug 13 '15 at 07:10
  • OK since your solution works as intended and this new issue is elsewhere in my file I will mark your answer as the solution and investigate further. Thanks – ProNotion Aug 13 '15 at 07:14