Thread: Running linux system commands

  1. #1
    Registered User
    Join Date
    May 2006

    Running linux system commands


    I'm trying to create a c program that when run opens a ssh tunnel to a computer, executes a few commands on that computer and closes the tunnel again.

    But I have no idea how to do this. I have tried to use "system()" to run linux commands but it stuffs up as I need to type in a password for my user.

    Is there some good and reasonably easy way to do this?


  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    Check out the popen() function.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Still in the egg
    Although the system() function is available in the UNIX systems, it is better to use fork()-execve() to run a command.

    You should have something like this
    int main()
    pid_t pid;
    if (pid == 0)
      /* here is the child*/
      execve(your command comes here);
    /* wait the child process to exit */
     return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  2. running system commands??
    By killdragon in forum C++ Programming
    Replies: 13
    Last Post: 09-25-2004, 02:49 PM
  3. system commands
    By darealnash in forum C++ Programming
    Replies: 8
    Last Post: 08-25-2004, 07:20 PM
  4. Linux Distro System Specs...
    By DarkViper in forum Tech Board
    Replies: 8
    Last Post: 02-29-2004, 07:07 PM
  5. system commands
    By volk in forum C++ Programming
    Replies: 3
    Last Post: 06-01-2003, 01:02 PM