How can I read data from standard input?

Welcome Forums General PowerShell Q&A How can I read data from standard input?

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 5 months ago.

  • Author
  • #34300

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

    I will appreciate help with the following question.

    In PowerShell, how can I read data from the standard output (Data that is generated by an automated process, and not by a user)?

    Consider the following scenario:
    A. A Java App launches a VBScript program (by running "cscript.exe")
    B. While the VBScript is running, the Java app writes data into the standard output.
    C. The VBScript reads this information from the standard input (using Wscript.StdIn.ReadLine) .

    I want to convert the VBScript program to PowerShell. I tried to use "Read-Host" to read data from the standard input, but it waits endlessly (probably waiting for user to press "Enter").

    So how can I do something similiar to VBScript "Wscript.StdIn.ReadLine" in PowerShell?

    Best Regards,


  • #34306

    Topics: 13
    Replies: 4872
    Points: 1,842
    Helping HandTeam Member
    Rank: Community Hero

    Just set a variable.

    $a = ping

    $a will contain whatever text ping.exe produced. Read-Host isn't for reading from stdout. It's for reading, as the name implies, from the console host. In my example here, $a will be a collection of strings. One string for each line of output produced by ping.exe. You could then enumerate those lines to parse them.

The topic ‘How can I read data from standard input?’ is closed to new replies.