簡體   English   中英

如何逐行讀取文件並將每一行作為參數輸入到 a.exe 文件並將 output 捕獲到 linux 中的另一個文件

[英]how to read a file line by line and each line as an argument input to a .exe file and capture the output to another file in linux

我嘗試編寫一個 shell 腳本逐行讀取 a.txt 文件,每一行都將作為 my.exe 文件的輸入,我還想捕獲.exe 文件的 output 並將其導出到另一個.txt 文件. 我的代碼喜歡這樣,但它不起作用。 當我嘗試像“./caculate.exe“1”這樣手動輸入時,程序也不將1作為輸入,仍然要求我再次手動輸入。

#!/bin/bash
while IFS= read -r LINE; do
  ./caculate.exe "$LINE"
done < data.txt > f.txt

如果calculate.exe通常從標准輸入中獲取輸入,則需要將變量pipe給它,而不是使用參數。

#!/bin/bash
while IFS= read -r LINE
do
    printf "%s\n" "$line" | ./calculate.exe
done < data.txt > f.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM