How to get a returned value from powershell and get it in a batch file?

前端 未结 5 841
我在风中等你
我在风中等你 2021-02-06 10:19

I\'m trying to execute a powershell from a batch file with the commande: Powershell .\\nameoffile.ps1

The PowerShell returns some values 1, 4, 0 and -1 . How can I get t

5条回答
  •  悲哀的现实
    2021-02-06 10:29

    What about something like this?

    test.bat

    @echo off
    powershell .\test.ps1 >output.log
    type output.log
    

    It just redirects the output of the powershell script to a text file and then outputs the contents of the text file to the console.

    Here is my test.ps1 file

    Write-Output "Hello World"
    Exit
    

    And here is the output:

    C:\temp\batchtest>test.bat

    Hello World

    C:\temp\batchtest>

提交回复
热议问题