What is the required syntax to redirect standard input/output on Windows PowerShell?
在Windows PowerShell上重定向标准输入/输出所需的语法是什么?
On Unix, we use:
在Unix上,我们使用:
$./program <input.txt >output.txt
How do I execute the same task in PowerShell?
如何在PowerShell中执行相同的任务?
2 个解决方案
#1
31
You can't hook a file directly to stdin, but you can still access stdin.
您不能将文件直接挂接到stdin,但您仍然可以访问stdin。
Get-Content input.txt | ./program > output.txt
#2
6
For output redirection you can use:
对于输出重定向,您可以使用:
command > filename Redirect command output to a file (overwrite)
command >> filename APPEND into a file
command 2> filename Redirect Errors
Input redirection works in a different way. For example see this Cmdlet http://technet.microsoft.com/en-us/library/ee176843.aspx
输入重定向以不同的方式工作。例如,请参阅此Cmdlet http://technet.microsoft.com/en-us/library/ee176843.aspx
#1
31
You can't hook a file directly to stdin, but you can still access stdin.
您不能将文件直接挂接到stdin,但您仍然可以访问stdin。
Get-Content input.txt | ./program > output.txt
#2
6
For output redirection you can use:
对于输出重定向,您可以使用:
command > filename Redirect command output to a file (overwrite)
command >> filename APPEND into a file
command 2> filename Redirect Errors
Input redirection works in a different way. For example see this Cmdlet http://technet.microsoft.com/en-us/library/ee176843.aspx
输入重定向以不同的方式工作。例如,请参阅此Cmdlet http://technet.microsoft.com/en-us/library/ee176843.aspx