[英]Redirect stdin and stdout in terminal to test program
我有一個從標准輸入讀取並輸出到標准輸出的程序。 我希望能夠通過終端進行測試。
我知道
./program < input_file # Redirects stdin
./program > output_file # Redirects stdout
output_file < ./program < input_file # Is this supposed to redirect stdin and stdout at the same time?
如果我在test.out
中有要比較output_file
的樣本 output 怎么辦? 我怎樣才能在一個 go 中做到這一點?
我嘗試了各種方法來做到這一點,但到目前為止還沒有運氣。
您對 output 文件的重定向錯誤。 您需要使用>
,而不是<
,並且它必須在文件名之前使用 go 。 就像在您的第二個示例中一樣 - 當您同時重定向輸入和 output 時沒有什么不同。
./program < input_file > output_file
您寫的內容是運行名為output_file
的程序,並首先從./program
重定向其輸入,然后從input_file
重定向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.