Automating execution of commands inside a program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating execution of commands inside a program
# 1  
Old 01-01-2012
Automating execution of commands inside a program

I have a program dnapars
I execute the program from command line as following:
./dnapars
The program then prompts me some message as a user menu from where I have to select a series of options in the order R U Y R. And then I copy the output file (outfile) in another result file.
I wrote the following script, but the execution hangs where it is supposed to execute the R option
Code:
    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    do
    cp ../../../EditDistanceRandomParsimonator/RAxML_parsimonyTree.test4D20RI$i.0 intree
    ./dnapars
    R      <----- This doesn't execute
    U
    Y
    R
    cp outfile result$i
    done

How can I make the script to run the options R U Y R under the dnapars program ?

Last edited by jim mcnamara; 01-02-2012 at 12:41 AM.. Reason: code tags please
# 2  
Old 01-02-2012
Quote:
Originally Posted by deeptisjains
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
do
cp ../../../EditDistanceRandomParsimonator/RAxML_parsimonyTree.test4D20RI$i.0 intree
./dnapars
R <----- This doesn't execute
U
Y
R
cp outfile result$i
done
It won't work this way.

1. What is dnapars program? Is it another shell script?
2. Is so, why not modify dnapars to take in the 4 options (R U Y R) directly from command line as Positional Parameters?
# 3  
Old 01-02-2012
Try this:
Code:
   for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    do
    cp ../../../EditDistanceRandomParsimonator/RAxML_parsimonyTree.test4D20RI$i.0 intree
    ./dnapars  <<EOF
R  
U
Y
R
EOF
    cp outfile result$i
    done

Note the last EOF is all the way over to the left. This is called a here document.
# 4  
Old 01-02-2012
Try this:
Code:
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    do
    cp ../../../EditDistanceRandomParsimonator/RAxML_parsimonyTree.test4D20RI$i.0 intree    
    echo "Enter Option"
    read option
    if [ "$option" == "R" ]
  then
   ./dnapars R
  fi
    
    echo "Enter Option"
    read option
    if [ "$option" == "U" ]
  then
   ./dnapars U
  fi
    
    # other options
    
    cp outfile result$i
    done


Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 01-02-2012 at 04:17 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execution of Shell Commands

I have a question: Where would I put the Command line (of any command) so that it executes every time I log on? Where would I put it if I want it to execute every time I start a new shell? (5 Replies)
Discussion started by: Nabeel Nazir
5 Replies

2. Shell Programming and Scripting

[Solved] Usage of shell commands inside a C program

Hi I have a program int main(int srgc, char *argv) { for(int i=1; i<50; i++) { system("dd if=/dev/zero of=file$i bs=1024 count=$i"); } return 0; } My doubt is how to use the "$i" value inside C code Please help (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

Execution of compressed program

I need UNIX scripts for polling, Uncompressing files and moving files between directory. Also trying to save file paths and any other variables in an independent file (.env) and use these at runtime by executing this file in the main script. (3 Replies)
Discussion started by: new2script
3 Replies

4. Shell Programming and Scripting

Parallel execution of command inside file

Hi all, I have the requirement to generate the file containing following command eval /path/ dsjob -logdetail projectname JOBNAME /path/ 1. The file contains the above command say about 150 times i,e only the JOBNAME changes in every command 2. The commands must be written in such a way... (2 Replies)
Discussion started by: sanjay mn
2 Replies

5. Programming

Help with C++ program execution.

//Find the root of the equation (x^2)-2 by bisection method. #include<iostream> using namespace std; double a,x; double f(double x) { return ((x*x)-2); } //Suppose the function is (x*x)-2. void calcx(double a1,double b1) { x =... (2 Replies)
Discussion started by: poonam.gaigole
2 Replies

6. UNIX for Dummies Questions & Answers

Execution of sh file inside vi editor...

Friends, Please need your help.... How can i run .sh file inside the vi editor in backend in HP Unix. (19 Replies)
Discussion started by: meetsubhas
19 Replies

7. Shell Programming and Scripting

Automating a Java program using KSH

Hi Guys, We have a java program that basically install updates to an existing software. The java program consist of several screens asking user for choices (please see below for a detailed example) *** Screen 1 *** Please choose the operation you want to perform: 1. Install new... (5 Replies)
Discussion started by: maddmaster
5 Replies

8. Shell Programming and Scripting

Automating executing commands on multiple tapes and changing (loading) them

The thing that we need to be able to do is: - Scanning tapes from failed backup jobs with bscan (a bacula command) - loading the next tape with the mtx command Bscan does unload tapes but does not load them. Bscan comes with this message when it's done with a tape: Mount Volume... (0 Replies)
Discussion started by: Tr00tY
0 Replies

9. Programming

Debugging Program during execution

I have made use of 'valgrind' and -finstrument-functions compiler option for debugging / analyzing code. Both the options lets us know the line / file being executed to some extent. Is there a generic way that lets program dump the file:line it is getting executed dumped to a log file during... (3 Replies)
Discussion started by: uunniixx
3 Replies

10. Programming

A program to trace execution of another program

Hi, I wanted to know if i can write a program using switches and signals, etc to trace execution of other unix program which calls c program internally. If yes how? If not with signals and switches then are there any other methods apart from debugging with gdb/dbx. (3 Replies)
Discussion started by: jiten_hegde
3 Replies
Login or Register to Ask a Question