在Windows PowerShell中重定向标准输入/输出

问题描述:

在Windows PowerShell上重定向标准输入/输出所需的语法是什么?在Windows PowerShell中重定向标准输入/输出

在Unix中,我们使用:

$./program <input.txt >output.txt 

如何在PowerShell中执行相同的任务?

+0

相关:http://stackoverflow.com/questions/16098366/can-i-send-some-text-to-the-stdin-of-an-active-process-under-windows – eckes 2016-06-15 12:38:48

您不能将文件直接挂接到stdin,但仍然可以访问stdin。

Get-Content input.txt | ./program > output.txt 
+0

该读整个'input.txt'文件进入内存。如果'input.txt'可能很大,请小心。 – 2017-11-08 05:34:15

输出重定向你可以使用:

command > filename  Redirect command output to a file (overwrite) 

    command >> filename  APPEND into a file 

    command 2> filename  Redirect Errors 

输入重定向作品以不同的方式。例如,请参阅此Cmdlet http://technet.microsoft.com/en-us/library/ee176843.aspx