# Writing a program that will send commands to another shell



## Aleran (Mar 5, 2003)

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?


----------



## symphonix (Mar 5, 2003)

You can use the ssh command to execute a remote command like this:

ssh usernameassword@hostaddress command

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

system("ssh jsmithassword@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_


----------



## symphonix (Mar 5, 2003)

Oops, smiley error! That's a colon between username and password.


----------



## Aleran (Mar 5, 2003)

Hmm interesting idea, which may be of some help, but as you say it may be difficult to issue multiple commands. Any other ideas?


----------



## rhg (Mar 6, 2003)

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.


----------



## Aleran (Mar 6, 2003)

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?


----------

