'<'运算符保留供将来使用

Bla*_*de3 44 powershell redirect io-redirection

我正在使用PowerShell并尝试运行以下命令:

.\test_cfdp.exe < test.full | tee test.log
Run Code Online (Sandbox Code Playgroud)

test.full是一个模拟test_cfdp.exe命令行输入的脚本.但是,我收到以下错误:

The '<' operator is reserved for future use.
Run Code Online (Sandbox Code Playgroud)

有没有其他方法(即cmdlet)我可以用来使这个命令在PowerShell中工作?

Rub*_*ink 45

PowerShell v1不支持此功能[从v5开始,它仍然没有...]

一个示例解决方法是:

Get-Content test.full | .\test_cfdp.exe | tee test.log
Run Code Online (Sandbox Code Playgroud)


ear*_*wth 22

还试试:

cmd /c '.\test_cfdp.exe < test.full | tee test.log'
Run Code Online (Sandbox Code Playgroud)


Szc*_*ski 7

在 PowerShell 版本 7 中,您仍然需要使用 Get-Content 来获取指定位置中项目的内容。例如,如果要将文件加载到 Python 脚本中并将结果写入文件。使用这个构造:

PS > Get-Content input.txt | python .\skript.py > output.txt
Run Code Online (Sandbox Code Playgroud)

或者显示并保存在文件中:

PS > Get-Content input.txt | python .\skript.py | tee output.txt
Run Code Online (Sandbox Code Playgroud)

或者切换到 cmd 以使用“<”运算符:

C:\>python .\skript.py < input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)