How to output something in PowerShell

前端 未结 7 938
北恋
北恋 2020-12-04 07:43

I am running a PowerShell script from within a batch file. The script fetches a web page and checks whether the page\'s content is the string \"OK\".

The PowerShell

相关标签:
7条回答
  • 2020-12-04 08:43

    I think the following is a good exhibit of Echo vs. Write-Host. Notice how test() actually returns an array of ints, not a single int as one could easily be led to believe.

    function test {
        Write-Host 123
        echo 456 # AKA 'Write-Output'
        return 789
    }
    
    $x = test
    
    Write-Host "x of type '$($x.GetType().name)' = $x"
    
    Write-Host "`$x[0] = $($x[0])"
    Write-Host "`$x[1] = $($x[1])"
    

    Terminal output of the above:

    123
    x of type 'Object[]' = 456 789
    $x[0] = 456
    $x[1] = 789
    
    0 讨论(0)
提交回复
热议问题