Writing a program that will send commands to another shell

Aleran

Registered
I know that if you are writting a C or C++ program, using the system(char *) function will send commands to the terminal command line. What I was wondering is how one could go about makeing a program that will launch another shell and then output its commands to that. For ex. If I write

system("ssh random.address.here");
system("commands to go to new ssh shell here");

The second command will only be executed outside of the ssh. So does anyone know how to make it so that the second line would send commands to the newly opened ssh?
 
You can use the ssh command to execute a remote command like this:

ssh username:password@hostaddress command

so, it might end up looking like this in your app:

system("ssh jsmith:password@mynet.com sh ~/sendbackup.sh");

or something like that. It would get a lot more tricky when you have a series of commands to execute, though.

no smiles now :) -Captain Code
 
Hmm interesting idea, which may be of some help, but as you say it may be difficult to issue multiple commands. Any other ideas?
 
Use popen() instead of system() to launch ssh. This will establish a pipe which you can use to send data to and receive data from.
 
I tried the popen() command for ssh but after the password has been entered I get a message:

"Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell."

This function does work for other shells, but do any of you have any ideas for SSH?
 
Back
Top