linux - How to understand and avoid non-interactive mode errors when running ispell from script? -


background

ispell basic command line spelling program in linux, want call collected list of file names. these file names recursively collected latex root file example. usefull when requiring spell recursively included latex files, , no other files. however, calling ispell command line turns out non-trivial ispell gives errors of form "can't deal non-interactive use yet." in cases.

(as side not, ideally call ispell programmatically java using processbuilder class, , without requiring bash. same error seems pester approach however.)

question

why ispell gives error "can't deal non-interactive use yet." in cases, when called in bash loop involving read method, not in other cases, shown in below code example?

the below minimal code example creates 2 small files (testfileone.txt, testfiletwo.txt) , file containing paths of 2 created files (testfileslisttemp.txt). next, ispell called testfileslisttemp.txt in 3 different ways: 1. of "cat" 2. first collecting names string, looping on substrings in collected string, , calling ispell each of them. 3. looping on contents of testfileslisttemp.txt directly, , calling ispell extracted paths.

for reaons third method not work, , yields error "can't deal non-interactive use yet.". why error occur, , how can prevented, and/or there perhaps variation of third approach work without errors?

#!/bin/bash   #ispell ./testfiles/ispelltestfile1.txt  # creating 2 small files , file file paths testing printf "file 1 contents" > testfileone.txt printf "file 2 contents. spelling eeeeror." > testfiletwo.txt printf "./testfileone.txt\n./testfiletwo.txt\n" > testfileslisttemp.txt  collected_latex_file_names_file=testfileslisttemp.txt   # approach 1: produce list of file names cat ,  # pass argumentto ispell # works ispell $(cat $collected_latex_file_names_file)  # second approach, first collecting file names long string,  # looping on substrings , calling ispell each 1 of them  files="" while read p; echo "read file $p"  files="$files $p" done < $collected_latex_file_names_file  printf "files list: $files\n"  latexname in $files;     echo "filename: $latexname"      ispell $latexname done   # third approach, not working  # ispell compmlains in case not working in non-interactive  # mode  #: "can't deal non-interactive use yet." while read p;        ispell "$p"  done < $collected_latex_file_names_file  

the third example not work, because redirect standard input. ispell needs terminal , user interaction. when write code this:

while read p;        ispell "$p"  done < $collected_latex_file_names_file  

everything read standard input program within loop taken $collected_latex_file_names_file file. ispell detects , refuses operating. however, can use "description redirection" make read p read file, , ispell "$p" read "real" terminal. do:

exec 3<&0 while read p;        ispell "$p" 0<&3 done < $collected_latex_file_names_file  

exec 3<&0 "copies" (saves) standard input (0, "terminal") descriptor 3. , later on redirect standard input (0) ispell descriptor, typing 0<&3 (you can omit 0 if like).


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -