1

I have developed an application in C that is a command line. The app has special keywords to output information. Currently I need to run a command to log into my application, than run a command to get an output, and finally exit the application.

Is there a way to combine my 3 lines into one? For Example, login, enter command, and exit sequentially? As you can see in the example below, if I can do this all in one line I wouldn't need to manually input every step.

./application -login [email protected]
> getstats
> exit    
./application -login [email protected]
> getstats
> exit
etc...

What I want is something like...

./application -login [email protected] && getstats && exit

Of course && is not what I'm looking for as it runs each command one at a time until. getstats and exit don't get run inside the .application but rather after I exit out of it...

Any tips would be great.

3
  • Not very professional, but just for testing give a try to something like : ./application -login [email protected]; sleep 5 && echo "getstats" &; sleep 10 && echo "exit" &; Feb 20, 2017 at 9:52
  • Please specify what language the application is written in.
    – agc
    Feb 22, 2017 at 21:40
  • @agc Updated. It is developed in C
    – sphchow
    Feb 24, 2017 at 7:59

1 Answer 1

2

If this application works with standard input, this may work:

printf 'getstats\nexit\n' | ./application -login [email protected]

If that doesn't work, you can try an expect script. You can see an example here.

3
  • I tried this method but session seems to hang. The system I am using doesn't have expect installed and I'd prefer a method that doesn't require a external application.
    – sphchow
    Feb 20, 2017 at 8:59
  • @sphchow if this doesn't work expect is probably your only other choice.
    – terdon
    Feb 20, 2017 at 15:16
  • @sphchow, The application is written in C. I'd suggest reconsidering which C function is used to input these command words, (i.e. getstats & exit) -- some C input functions work well with STDIN, perhaps the application can be modified to use one of those STDIN friendly functions.
    – agc
    Feb 24, 2017 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .