我需要讀取一個JSON文件:批處理文件,讀取JSON文件轉換成字符串
{
"key": {
"subkey": "value"
}
}
這樣我就可以把它作爲一個參數的命令:
program -e SETTINGS=<JSON FILE AS STRING>
我需要讀取一個JSON文件:批處理文件,讀取JSON文件轉換成字符串
{
"key": {
"subkey": "value"
}
}
這樣我就可以把它作爲一個參數的命令:
program -e SETTINGS=<JSON FILE AS STRING>
合併的答案,這些問題...
...我們可以寫出下面的批處理文件:
:: Make it possible to read immediate value of variable using !variable! syntax.
setlocal enabledelayedexpansion
:: Read file "test.json" into variable data, removing line breaks.
set data=
for /f "delims=" %%x in (test.json) do set "data=!data!%%x"
:: Escape double quotes in data
set data=%data:"=\"%
:: Finally call program with the entire content of the JSON file as parameter
program -e "SETTINGS=%data%"
注意使用cmd.exe
命令的處理器,maximum length for a commandline and also for environment variables is 8191 characters的時候,所以這顯然限制了JSON文件的最大尺寸可以通過。
也許[this](https://stackoverflow.com/a/12977190/6738015)是你想要的! – Compo
嘗試自動化之前,我會檢查它是否與這樣的縮寫字符串一起使用,轉義內部雙引號'program -e「SETTINGS = {\」key \「:{\」subkey \「:\」value \「 }}''' – LotPings