PowerShell: how to capture (or suppress) write-host

后端 未结 3 1991
清酒与你
清酒与你 2021-01-20 00:37

I have a script call \"a.ps1\":

write-host \"hello host\"
\"output object\"

I want to call the script and obtain the output object, but I a

3条回答
  •  礼貌的吻别
    2021-01-20 00:41

    The output object i.e. "output object" is output to standard output. So I don't think you want to suppress standard output. If you don't want anything printed to the console don't use Write-Host as that bypasses all streams (stdout, stderr, warning, verbose, debug) and displays directly to the host. There is currently no easy mechanism I'm aware of to redirect host output.

    BTW why do you need to write "hello host" to the console if you don't want to see it displayed later?

提交回复
热议问题