"C++ Primer (5th Edition)" program redirection problem

1. The redirect method mentioned in the book

Insert picture description here

2. Problems in actual use

  • In Windows PowerShell, .\项目1.exe < .\data.txtredirecting according to the method mentioned in the book will report an error:
所在位置 行:1 字符: 11
+ .\项目1.exe < .\data.txt
+           ~<”运算符是为将来使用而保留的。
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported

3. Ways to solve the problem

  • Refer to the blogger's answer: https://blog.csdn.net/fjjaylz/article/details/86663013
  • If you only input, use the following command:
    Get-Content .\data.txt | .\项目1.exe
  • If only output, use the following command:
    .\项目1.exe | tee out.txt
  • For both input redirection and output redirection, use the following command:
    Get-Content .\data.txt | .\项目1.exe | tee out.txt

Guess you like

Origin blog.csdn.net/weixin_41754258/article/details/112424823