-1

I have a config file "config.json"...

{
   host: "abc",
   port: "59300"
}

I want to extract the values of host & port and feed it to a bat file, the contents of which read,

@echo off
cmd /c "cd /d %ZOWE_HOME%\zlux-app-server\bin && nodeServer.bat --allowInvalidTLSProxy=true -h %host% -P %port% -p 9999"

How to accomplish this in a single .bat file?

  • 2
    Don't use internal batch file comnands to try to read and parse `json` data. Use, or at least get help from, PowerShell, which has native methods of doing that. – Compo Jun 10 '23 at 19:25

1 Answers1

-1

Insert these lines between your two lines

FOR /f "usebackqtokens=1,2delims=:, " %%b IN ("u:\your files\q76447808.txt") DO (
 FOR %%e IN (host port) DO IF "%%e"=="%%b" SET "%%b=%%~c"
)

ECHO host=%host% port=%port%

Notes :
It's SOP to follow with a setlocal line to keep the environment clean
The first three lines of this code may be compated to one. I left it at 3 for clarity
The ECHO line is simply to show the results
You would need to understand the delayed expansion trap if you want to further compact the code (which is not necessary in any case)

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Just to make you aware Magoo, that in these confguration files, value names can, and often are, repeated. Also, very often, _(really should be)_, both key pairs, are doublequoted too. – Compo Jun 10 '23 at 20:14
  • @compo : Can only go on the example posted. – Magoo Jun 10 '23 at 20:16