0

I am writing a cmd batch script that runs a module called Docsify. I want to get the URL from its output and open it in a browser. The problem I have is:

  1. It doesnt echo the output (basically just a blank display after calling the command)
  2. I need to open it in a browser

(Worth mentioning though that when I manually open localhost:3000 in the browser, then the page actually loads fine. I am not sure why the cmd command isnt able to display the proper output)

Here is my code:

FOR /F "tokens=*" %%A IN ('docsify serve ./docsify') DO (
  echo %%A
)

This is my EXPECTED output:

Serving C:\Users\me\Desktop\NodeJS\node_modules\doc-viewer\docsify now.
Listening at http://localhost:3000

But then as I've mentioned what I'm getting is just a blank display.

I also tried to just manually enter the command and force it to open localhost:3000

docsify serve ./docsify
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE https://localhost:3000

Then the docsify output is displayed in my console, as expected. But then I need my script to open IE and go to localhost:3000. It currently doesn't do that because it is 'listening' at port 3000 (it stays on this prompt until I terminate the cmd). Is there anyway I can call a command to open IE while docsify is listening?

Any thoughts?? Thanks!

kzaiwo
  • 1,558
  • 1
  • 16
  • 45
  • `docsify serve ./docsify`, or `docsify s ./docsify` by default will run on port `3000`, unless it is explicitly told otherwise, _(using the `--port`, or `-p` option)_! – Compo May 11 '22 at 08:53
  • `for /f ... in ('program') ...` generally only gets the data and starts parsing it _when the program exits_ (aka stops, finishes, completes). You are running a server that doesn't exit, so `for /f` never gets the data from it. – dave_thompson_085 May 11 '22 at 09:17
  • @compo - Thanks, yes I am aware of that.. But any idea how can I make my script open up a browser pointing to localhost:3000? My cmd is stuck at the listening.. – kzaiwo May 11 '22 at 09:18
  • @dave_thompson_085 ooh that makes sense. Thank you for enlightening me! Any idea though on how to open the browser while the server is running? – kzaiwo May 11 '22 at 09:19

1 Answers1

0

I finally found a solution. Basically I run the docsify server through docsify serve on a separate cmd window then add a timer before opening localhost:3000 on the browser.

start cmd.exe /c docsify serve ./docsify
timeout /t 3
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE http://localhost:3000
kzaiwo
  • 1,558
  • 1
  • 16
  • 45