[英]Control output of c++ program using makefile
我有一個名為 print-word-length.cc 的可執行文件,它使用 *.txt 文件打印單詞的長度。
所以在我的 makefile 中,. ./print-word-length </dir/dictionary.txt
打印出字典中的單詞。
我將如何 go 僅打印 dictionary.txt 中的前 10 個單詞長度?
我試過head -n 10./print-word-length </dir/dictionary.txt
,但它打印出亂碼。
你試過./print-words.cc </dir/dictionary.txt | head -n 10
./print-words.cc </dir/dictionary.txt | head -n 10
? 這將打印 output 的前十行。
這不是 makefile 問題,而是 shell 腳本問題。 通過在 shell 提示符下編寫 shell 命令來解決問題,然后將相同的解決方案放入 makefile 中。
head
實用程序打印它從標准輸入或文件中讀取的第一行。 它不會運行您將其作為參數提供的命令。
它正在打印程序文件內容的前 10 行,正如您所說,這是二進制“亂碼”。
這就是管道的用途:
./print-word-length.cc </dir/dictionary.txt | head -n10
這表示:啟動print-word-length.cc
並對其進行設置,以便將打印到 output 的任何內容作為輸入發送到head
命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.