1

I'd like to ask what is the most common way to parse user input to the executable program, in particular on Linux. I tried to invoke bash script that contains the following lines:

BIN_FILE=<filepath>
FLAG=<flag>\n

${BIN_FILE}
echo -ne ${FLAG}
[...]

but since the executed program is a separate thread the echo line of my script is not processed until the program terminates.

In adnvace thank you for your answers! BR -M

Marek Bocian
  • 115
  • 10
  • do you mean simulate user's input from bash script? then ```echo $FLAG | ${BIN_FILE}``` . Please rephrase your question to avoid confusion. Right now your question is not clear. – Maxim Sagaydachny Feb 13 '20 at 16:13
  • 1
    Yes, that is exactly what I mean - thank you for the suggestion. I'll rephrase the question. – Marek Bocian Feb 13 '20 at 16:25
  • Does this answer your question? [Passing arguments to an interactive program non-interactively](https://stackoverflow.com/questions/14392525/passing-arguments-to-an-interactive-program-non-interactively) – Maxim Sagaydachny Feb 13 '20 at 16:31
  • 1
    Well, yes and no.. Because I believe this solutiion apply's to the single instance of the prompt (moreover at the beginning of the program execution ?). What would be the solution to the e.g. following problem - program that reads the user input at the start and end of the program? Again, thank you. -M – Marek Bocian Feb 13 '20 at 16:50
  • 2
    Mr Mindreader is out on vacation right now. Please try again to rephrase your question for us mere mortals to be able to help you :-) Could you please describe expected output of binary, which app questions should be answered by script and which by user directly and probably someone will come up with solution which uses ```expect``` or something different – Maxim Sagaydachny Feb 13 '20 at 16:59
  • Side comment: This is why best practice is for utilities to take command-line arguments rather than trying to interact with the user. (User interaction can be a handy option, but for scripting command-line arguments rule.) – rici Feb 13 '20 at 18:18
  • @MaximSagaydachny, ok let me put this way: Imagine that we have a C program that reads input it the following manner: "Please enter num value one:" "Please enter num value two:" and so on ... I believe that single input redirection would not be sufficient since it would interact with the 1st prompt dialog. I am trying now to open the program in the separate terminal session,get the PID of that process and redirect consecutive input using: echo "" > /proc//fd/0 If I success I'll share the results withU – Marek Bocian Feb 14 '20 at 09:02
  • And technically, yes I believe I could write a TCL script that would simulate the user interaction. I was just curious if I could do that within the shell / bash itself (knowing the Linux capabilities I believe there is a way). :) – Marek Bocian Feb 14 '20 at 09:09

0 Answers0