Suppose you're using a CLI too that takes multiline input from stdin and processes it one line at a time, printing the results of each line sequentially.

What is the correct behavior in case one of these stdin lines causes an error? To immediately halt the execution or to print an error message to stderr and continue on the next line? Do you have an example of a CLI tool that does it right?

Reply to this note

Please Login to reply.

Discussion

not yet

I think it depends on if each line is serial, if not then probably okay to continue. Either print the stderr or wait and print it before closing (or possibly botth). The cli for rsync, could be close.

grep "apple" nonexistent.txt sample.txt

grep: nonexistent.txt: No such file or directory

sample.txt:apple

sample.txt:apple pie

sed and awk should behave similarly.

This isn’t really multiline tho. So nvm

Not sure if it is the same case that you want

Usually i just redirect stdout and stderr to proper files:

```

cat filetoread.log | while read -r line;do

echo $line | another_script.sh 1>>/tmp/stdout.log 2>>/tmp/stderr.log

done

```

and run another script tail the error log:

```

tail -F /tmp/stderr.log | while read -r line;do

echo $line | do_whatever.sh

done

```

My personal preference is to loop until the user enters an input that is valid or the user quits. It would be nice if the app tells me why my input is not valid and how to quit if I do not have the data at the moment. If everything is good, then move on to the next input.

Do you have an example of a CLI tool that does it right? Reference Linux command ‘watch’