繁体   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