我正在尝试Select-String
在 PowerShell 中使用来查看docker inspect
命令的结果,但该Context
属性似乎无法正常工作。
如您所知,docker inspect
返回正常的 JSON 作为输出,例如:
[
{
"Id": "c8a5810c62d8dbea11335be561522b4a3df53b9ddcae5531ae06483926c5f992",
"Created": "2018-07-31T17:16:53.8689464Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 13613,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-07-31T17:16:54.6460418Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
...
},
...
]
在没有任何附加参数的情况下运行sls
(别名):Select-String
并运行它Context
:
如您所见,输出是相同的,我在输出中看不到前后行
我可以用来grep
做我想做的事;例如,
docker inspect devtest | grep Mounts -B 5 -A 5
输出grep
:
但我想知道为什么Select-String
不起作用。
更新
正如@iRon 建议的那样,我什至尝试将输出保存到文件中,然后Select-String
在文件上使用(示例文件):
所以,我真的很困惑发生了什么。因为对于@iRon,它工作正常。
更新 2
我注意到如果我做这样的事情:
$result = $json | Select-String "Mounts" -Context 5`
然后当我查看$result[0].Context.PreContext
(and PostContext
) 时,它们在输入中包含前后行,但由于某种未知原因,它们没有打印到控制台