LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Excecuting binaries on linux (https://www.linuxquestions.org/questions/linux-newbie-8/excecuting-binaries-on-linux-805510/)

brimlightdiamonds 05-02-2010 01:44 PM

Excecuting binaries on linux
 
Guys,
I am looking for a clue in shell or ant script, where I excecute a binay file on linux. For example ./myfile.bin which ask me few questions.

./myfile.bin ...........................100%

Please enter hostname:

done.

I would like to automate this process where I want to pass the hostname as a variable or read from a file is it possible? If yes any sample`s on this.

Remember, I can do if this was a shell script ($1) but not sure when its binary.

pixellany 05-02-2010 01:55 PM

Very often you can simply pass a parameter when calling the program. I'm not sure exactly how to write the code so it works either way, but I've seen lots of utilities that do.
Example: run "adduser" and it asks you first for the username. But you can also run "adduser username".

Regardless, I don't think this behavior depends on whether it is a compiled binary or a shell script.

You also might want to look at the "expect" command.

brimlightdiamonds 05-02-2010 06:43 PM

Any other answers ?

Bratmon 05-02-2010 07:04 PM

I'd try something like creating a text file in the format:
Code:

answertoquestion1
answertoquestion2
answertoquestion3
...

And pipe that to the stdin of the program. Not sure if that'd work or not.

pixellany 05-02-2010 08:25 PM

Since the OP has a specific program in mind, the first step is to try in real time calling the program with the argument(s) that it expects. If that works, then I assume that getting them from a file will also work---but I don't see the benefit.

TedHornsby84 05-02-2010 09:01 PM

I'm not sure if this is the answer you're looking for, but in bash scripting any arguments passed via the command line (e.g. ./myfile.sh arg1 arg2 etc.) can be accessed in the script through the variables $1, $2, etc. As in, arg1 = $1, arg2 = $2. These do not need to be defined by you, as a local variable would. I hope this helps, but if I'm way off, clarify your question a little bit for me and I'll help the best I can.

brimlightdiamonds 05-03-2010 11:13 PM

To clarify more, If I run a binary or exe any installation program say JVM (JDK) autoinstallation. I want to automate the excecution by passing the value automatically either from a file or as a variable. But I tried to pass as a varible, it does not work.

So here is more specific information on what I need.
Shell/Ant/Java Program --> excecute the binary(or exe) --> auto-fills the information.

sundialsvcs 05-04-2010 08:35 AM

All Linux programs read their "terminal input" from STDIN and send their "normal output" to STDOUT and their "error-message or status output" to STDERR.

All three of these names are "standard file-handles" which all processes have.

You can therefore "stuff" any program with a set of responses by "piping" input into them, or by using the shell to "redirect" their STDIN from some other source.

Look up the bash-shell operators "|" (called pipe, it is a vertical-bar); and "<", ">", and ">>" (which allow you to redirect the input and output and error streams).

I am "redirecting" :) your question because there is a lot of existing material out there which explains the concept very much better than I can.

catkin 05-04-2010 08:45 AM

Try Here Documents and Here Strings; they are good at feeding lines to executables, including variables, and allow everything to be contained within a single script or command.


All times are GMT -5. The time now is 10:07 AM.