How can I read data from standard input?

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,


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.