LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   entering automatically the value that the software asks during processing of a file (https://www.linuxquestions.org/questions/programming-9/entering-automatically-the-value-that-the-software-asks-during-processing-of-a-file-849299/)

nesrin 12-09-2010 10:32 AM

entering automatically the value that the software asks during processing of a file
 
Hello,
I use the below loop to process each file (listed in a text file) with a software. During processing the software asks me to enter a value and continues processing of that file after i enter the value. I have those values stored in a text file "myfile". what i want is to get the values directly from myfile when the software asks
"please enter the title:"

I dont want to enter them all manually. But i could not figure out how to code this in Bash script.

Code:

for ((i=1,i<=$NR,i++)); do

--command of the software comes here--

done

Thanks in advance
regards

alunduil 12-09-2010 10:38 AM

To pass a file as input to a command you can use the input redirection '<' (e.g. echo < stuff.txt).

Regards,

Alunduil

theNbomr 12-10-2010 04:06 PM

To rephrase your question, you have one program that you want to run iteratively, and on each iteration, supply commandline arguments to that program. The commandline arguments are to be read from a file, each time taking the next argument(s) in the list.
If so, then you seem to be mostly on the way to success already.

This will work if the data for each iteration is on one line of the argument data file.

Code:

while read arg1 arg2; do
  echo "The args are : [1]\"$arg1\"  [2]\"$arg2\"
done < datafile

--- rod.

AnanthaP 12-10-2010 07:42 PM

In *nix, most system utilities follow the standard of permitting redirected input as source, but it is not axiomatic that your application software will do the same (allow input redirected). Certainly in a GUI environment, it should have been specifically programmed before hand.Try anyway with your software.

But I think that your software asks a series of questions like "Please enter the title:", .. and so on in a specified sequence and that is what you would put in the text file.

Try with the following:
mysoftware < myfile.txt

Details about the software might help.

nesrin 12-13-2010 04:50 AM

thank you all,
simple input redirection "<" solves my problem actually I thought it is more complicated. thanks a lot.
@ theNbomr: thanks for rephrasing my question. That is exactly what i meant, and meanwhile i am also learning how to formulate questions better.
@ AnanthaP: I am using Gamma remote sensing software, and it works well with redirection.


All times are GMT -5. The time now is 06:20 PM.