LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2010, 02:44 PM   #1
brimlightdiamonds
LQ Newbie
 
Registered: May 2010
Posts: 3

Rep: Reputation: 0
Question 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.

Last edited by brimlightdiamonds; 05-02-2010 at 02:46 PM.
 
Old 05-02-2010, 02:55 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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.
 
Old 05-02-2010, 07:43 PM   #3
brimlightdiamonds
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Question

Any other answers ?
 
Old 05-02-2010, 08:04 PM   #4
Bratmon
Member
 
Registered: Jul 2009
Location: 75.126.162.205:80
Distribution: Arch / Mint 17
Posts: 297
Blog Entries: 3

Rep: Reputation: 50
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.
 
Old 05-02-2010, 09:25 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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.
 
Old 05-02-2010, 10:01 PM   #6
TedHornsby84
Member
 
Registered: Mar 2010
Location: Oak Cliff, TX
Distribution: Gentoo
Posts: 35

Rep: Reputation: 2
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.
 
Old 05-04-2010, 12:13 AM   #7
brimlightdiamonds
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 05-04-2010, 09:35 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,697
Blog Entries: 4

Rep: Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028
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.
 
Old 05-04-2010, 09:45 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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.

Last edited by catkin; 05-04-2010 at 09:46 AM. Reason: Cleaner, sleeker ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux binaries syntacticalerror Linux - Newbie 5 07-30-2008 10:47 PM
Linux binaries for FreeSpace 2? MathBluster Linux - Games 0 08-07-2007 10:54 PM
excecuting command in colour at ~/.bashrc kernel_geek Programming 2 02-08-2007 06:33 AM
Sims 2 for Linux (or at least binaries) darkflounder Linux - Games 17 01-20-2007 08:38 PM
Excecuting script as different user... The Jesus Programming 2 04-13-2002 04:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration