Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Results 1 to 6 of 6
  1. #1
    Aleran is offline Registered User
    Join Date
    Dec 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Writing a program that will send commands to another shell

    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?

  2. #2
    symphonix's Avatar
    symphonix is offline Scratch & Sniff Committee
    Join Date
    Jul 2001
    Location
    The Australian Jungles
    Posts
    4,025
    Thanks
    2
    Thanked 6 Times in 5 Posts
    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
    Last edited by Captain Code; March 5th, 2003 at 10:05 AM.
    - iMac G5 1.8GHZ 17" | SuperDrive | 160GB | 512MB | Airport Extreme | Bluetooth Keyboard & Mouse | Wacom Intuos II
    - Pentax *ist DL - JVC MiniDV Camcorder - Airport Express - iPod Nano 1gb white

  3. #3
    symphonix's Avatar
    symphonix is offline Scratch & Sniff Committee
    Join Date
    Jul 2001
    Location
    The Australian Jungles
    Posts
    4,025
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Oops, smiley error! That's a colon between username and password.
    - iMac G5 1.8GHZ 17" | SuperDrive | 160GB | 512MB | Airport Extreme | Bluetooth Keyboard & Mouse | Wacom Intuos II
    - Pentax *ist DL - JVC MiniDV Camcorder - Airport Express - iPod Nano 1gb white

  4. #4
    Aleran is offline Registered User
    Join Date
    Dec 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm interesting idea, which may be of some help, but as you say it may be difficult to issue multiple commands. Any other ideas?

  5. #5
    rhg
    rhg is offline Registered User
    Join Date
    Dec 2002
    Location
    Velbert, Germany
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  6. #6
    Aleran is offline Registered User
    Join Date
    Dec 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

 

 

Similar Threads

  1. How Do I Go About Writing This Program?
    By bkaron in forum Software Programming & Web Scripting
    Replies: 10
    Last Post: November 10th, 2003, 08:33 AM
  2. [FAQ] - Setting the UNIX shell prompt
    By michaelsanford in forum HOWTO & FAQs
    Replies: 4
    Last Post: March 27th, 2003, 01:25 PM
  3. Can unix commands be called from a C program?
    By VGZ in forum Mac OS X System & Mac Software
    Replies: 6
    Last Post: January 26th, 2001, 11:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •