![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | read from standard input (stdin) Hi, I want to write a power shell script that reads from the standard input. I try to call my script stored in test.ps1 like this: >powershell -command .\test.ps1 < .\test.txt or like this: >echo foobar | powershell -command .\test.ps1 I just want to access the content of stin. But I don't know how to do this. Reading by Read-Host only waits for keyboard input. Can someone help me please. Tanks and Regards tiefseeruebe |
My System Specs![]() |
| | #2 (permalink) |
| | Re: read from standard input (stdin) On Jul 30, 2:52 pm, tiefseeruebe <tiefseeru...@discussions.microsoft.com> wrote: > Hi, > > I want to write a power shell script that reads from the standard input. I > try to call my script stored in test.ps1 like this: > > >powershell -command .\test.ps1 < .\test.txt > > or like this: > > >echo foobar | powershell -command .\test.ps1 > > I just want to access the content of stin. But I don't know how to do this. > Reading by Read-Host only waits for keyboard input. > > Can someone help me please. > > Tanks and Regards > > tiefseeruebe try read-host. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: read from standard input (stdin) On Jul 30, 3:14 pm, y.bobzh...@gmail.com wrote: > On Jul 30, 2:52 pm, tiefseeruebe > > > > > > <tiefseeru...@discussions.microsoft.com> wrote: > > Hi, > > > I want to write a power shell script that reads from the standard input. I > > try to call my script stored in test.ps1 like this: > > > >powershell -command .\test.ps1 < .\test.txt > > > or like this: > > > >echo foobar | powershell -command .\test.ps1 > > > I just want to access the content of stin. But I don't know how to do this. > > Reading by Read-Host only waits for keyboard input. > > > Can someone help me please. > > > Tanks and Regards > > > tiefseeruebe > > try read-host.- Hide quoted text - > > - Show quoted text - sorry, I didn't read the last line. Ignore my reply. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: read from standard input (stdin) Input redirection is not implemented in PowerShell v1.0. Shay http://scriptolog.blogspot.com > Hi, > > I want to write a power shell script that reads from the standard > input. I try to call my script stored in test.ps1 like this: > >> powershell -command .\test.ps1 < .\test.txt >> > or like this: > >> echo foobar | powershell -command .\test.ps1 >> > I just want to access the content of stin. But I don't know how to do > this. Reading by Read-Host only waits for keyboard input. > > Can someone help me please. > > Tanks and Regards > > tiefseeruebe > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: read from standard input (stdin) "tiefseeruebe" <tiefseeruebe@discussions.microsoft.com> wrote in message news:39D8DA88-DED4-4AC8-BF42-C0F1E0ACF6B5@microsoft.com... > Hi, > > I want to write a power shell script that reads from the standard input. I > try to call my script stored in test.ps1 like this: > >>powershell -command .\test.ps1 < .\test.txt > > or like this: > >>echo foobar | powershell -command .\test.ps1 > > I just want to access the content of stin. But I don't know how to do > this. > Reading by Read-Host only waits for keyboard input. Input redirection with "<" is not supported in PowerShell. However you can easily read the content of a file and pass it to the next command in the pipeline like this: get-content test.txt | test.ps1 If you want to kick off the whole process from a CMD session, you should be able to do it like this: powershell -command "& {get-content c:\test\test.txt | c:\test\test.ps1}" Note that you will probably have to use absolute paths for the text file as well as for the script (unless it is in the PATH). Jacques |
My System Specs![]() |
| | #6 (permalink) |
| | RE: read from standard input (stdin) As others have mentioned, the '<' operator is not supported in PowerShell v1.0. It is reserved for future use. However, your second shot is actually the way to go in version 1. Note that when invoking the command you need to be aware of the differences between the various command shells that you might be using. For example quoting, escaping, variable interpolation etc. works quite different in PowerShell, cmd.exe and bash. ### PowerShell test script PS C:\> get-content C:\write-input.ps1 $input | foreach {write-host $_} ### example for cmd.exe C:\>echo bratwurst, banane | powershell -noprofile -command "$input | . C:\write-input.ps1" bratwurst, banane ### example for PowerShell PS C:\> echo bratwurst, banane| powershell -noprofile -command '$input | . C:\write-input.ps1' bratwurst banane Also be aware of the different ways the comma is interpreted in each command shell. -- greetings dreeschkind "tiefseeruebe" wrote: > Hi, > > I want to write a power shell script that reads from the standard input. I > try to call my script stored in test.ps1 like this: > > >powershell -command .\test.ps1 < .\test.txt > > or like this: > > >echo foobar | powershell -command .\test.ps1 > > I just want to access the content of stin. But I don't know how to do this. > Reading by Read-Host only waits for keyboard input. > > Can someone help me please. > > Tanks and Regards > > tiefseeruebe |
My System Specs![]() |
| | #7 (permalink) |
| | RE: read from standard input (stdin) Thanks for the responses. The point seems to be the parameter -noprofile. With out that it does not work as expected. However I don't understand that. Regards tiefseeruebe "dreeschkind" wrote: > As others have mentioned, the '<' operator is not supported in PowerShell > v1.0. It is reserved for future use. > However, your second shot is actually the way to go in version 1. > Note that when invoking the command you need to be aware of the differences > between the various command shells that you might be using. For example > quoting, escaping, variable interpolation etc. works quite different in > PowerShell, cmd.exe and bash. > > ### PowerShell test script > PS C:\> get-content C:\write-input.ps1 > $input | foreach {write-host $_} > > ### example for cmd.exe > C:\>echo bratwurst, banane | powershell -noprofile -command "$input | . > C:\write-input.ps1" > bratwurst, banane > > ### example for PowerShell > PS C:\> echo bratwurst, banane| powershell -noprofile -command '$input | . > C:\write-input.ps1' > bratwurst > banane > > Also be aware of the different ways the comma is interpreted in each command > shell. > > -- > greetings > dreeschkind > > "tiefseeruebe" wrote: > > > Hi, > > > > I want to write a power shell script that reads from the standard input. I > > try to call my script stored in test.ps1 like this: > > > > >powershell -command .\test.ps1 < .\test.txt > > > > or like this: > > > > >echo foobar | powershell -command .\test.ps1 > > > > I just want to access the content of stin. But I don't know how to do this. > > Reading by Read-Host only waits for keyboard input. > > > > Can someone help me please. > > > > Tanks and Regards > > > > tiefseeruebe |
My System Specs![]() |
| | #8 (permalink) |
| | RE: read from standard input (stdin) "tiefseeruebe" wrote: > Thanks for the responses. The point seems to be the parameter -noprofile. > With out that it does not work as expected. However I don't understand that. Can you be a little bit more specific when you say "does not work as expected"? Do you get any error messages? The parameter -noprofile will just tell PowerShell not to load your profile at startup ($profile). It should work without the parameter as well. -- greetings dreeschkind |
My System Specs![]() |
| | #9 (permalink) |
| | RE: read from standard input (stdin) Strange: you are right. I was sure that it didn't work w/o that -noprofile. However now, as i try, there is no difference. I don't remember what I did, it was late already. Thanks anyway. regards tiefseeruebe "dreeschkind" wrote: > "tiefseeruebe" wrote: > > > Thanks for the responses. The point seems to be the parameter -noprofile. > > With out that it does not work as expected. However I don't understand that. > > Can you be a little bit more specific when you say "does not work as > expected"? > Do you get any error messages? The parameter -noprofile will just tell > PowerShell not to load your profile at startup ($profile). It should work > without the parameter as well. > > -- > greetings > dreeschkind |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| VbSystemModal type functionality for Read-Host input | PowerShell | |||
| Read console input in Do/While Loop. | PowerShell | |||
| PowerShell: how to read Pipe.Input from a script? | PowerShell | |||
| PowerShell: how to read Pipe.Input from a script? | PowerShell | |||
| How to read CSV to another command's input? | PowerShell | |||