我需要读取一个json文件:
{
"key": {
"subkey": "value"
}
}
因此,我可以将其作为参数传递给命令:
program -e SETTINGS=<JSON FILE AS STRING>
我需要读取一个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
命令处理器时,命令行和环境变量的最大长度为8191个字符,因此这显然会限制您可以传递的JSON文件的最大大小。
program -e "SETTINGS={\"key\":{\"subkey\": \"value\"}}"
。 - user6811411