当我从 运行 Window 运行 时为什么不能在 powershell 中跟踪日志?

Why can't I tail a log in powershell when I run it from the run Window?

如果我打开 Power Shell window 和 运行 下面的命令它工作正常...

get-content -Path C:\Users\user\AppData\Local\Temp\tmpDF49.tmp -wait

但是如果我打开 运行 菜单 (WINKEY+R) 然后 运行 它就像这样:

powershell -command 'get-content -Path C:\Users\user\AppData\Local\Temp\tmpDF49.tmp -wait'

它打开一个 powershell window 然后就关闭了...

我也从 powershell 脚本中尝试过同样的事情,它只是关闭了......就像 运行 菜单一样:

[Diagnostics.Process]::Start("powershell.exe", "-command `"get-content -Path $($tmpFile) -wait`"")

它不应该继续等待并尝试跟踪日志吗?

您需要 运行 运行 行中的以下内容:

powershell -NoExit -command "Get-Content -Path C:\Users\user\AppData\Local\Temp\tmpDF49.tmp -wait"

-command 开关旨在 运行 提供的命令并退出,除非指定 -NoExit。根据设计,-NoExit 也必须位于 -command 参数之前。

运行 PowerShell.exe -Help 会泄露此信息。有人告诉我并非所有信息都是准确的,但上面的陈述似乎是准确的。