简体   繁体   中英

cmd - save command output in a parameter then open browser

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM