在$()子表达式中使用Write-Host始终输出到字符串的开头,而不管其位置如何。
例如:
"This is $(Write-Host 'now at the beginning' -NoNewline)"输出:
now at the beginningThis is其他cmdlet在这里可以正常工作(例如"Today is $((Get-Date).DayOfWeek)"、Today is Friday)。
写主机有什么不同?
发布于 2016-10-01 12:14:01
它不会“输出到字符串的开头”,它会以“向后”的顺序向主机写入两次。
"abc $()"是一个字符串文字,它包含一个sub-expression.$()$()写入屏幕now at the beginning但不返回任何内容"abc""abc"将写入屏幕now at the beginningabc这不是在做你建议的事情:
"abc $(write-host 'hi')""hiabc"https://stackoverflow.com/questions/39802919
复制相似问题