Thread: Execute a command from C code in a different terminal

  1. #1
    Registered User poornaMoksha's Avatar
    Join Date
    Sep 2011
    Location
    India
    Posts
    41

    Execute a command from C code in a different terminal

    Hi,

    I want to write a C program that can launch an executable in a new shell different from the controlling shell. So what I did is :

    1) Used the system("gnome-terminal") function to launch a new shell
    2) Opened it as file using its tty name (like : /dev/pts/<> )
    3) wrote something like : fwrite("./hello\n", sizeof("./hello\n"), 1, fp);

    I got a new terminal, it opened like a file, fwrite() was also done but './hello' did not work like a command. It stood there like a dead text.

    Please help!!!!

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Nope sorry that's not going to work...

    C programs require compilation before they will run.

  3. #3
    Registered User poornaMoksha's Avatar
    Join Date
    Sep 2011
    Location
    India
    Posts
    41
    Quote Originally Posted by CommonTater View Post
    Nope sorry that's not going to work...

    C programs require compilation before they will run.
    I did not get you.
    I have compiled my C program and then executed it, that's how I told that whats happening and as far as the binary 'hello' is considered..it is also present...

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Try something like print the current directory command (I can not remember the Linux/Unix command for that.)

    It is likely the new shell has a different current directory than the one you think it has.

    Tim S.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    1
    Quote Originally Posted by poornaMoksha View Post
    Hi,

    I want to write a C program that can launch an executable in a new shell different from the controlling shell. So what I did is :

    1) Used the system("gnome-terminal") function to launch a new shell
    2) Opened it as file using its tty name (like : /dev/pts/<> )
    3) wrote something like : fwrite("./hello\n", sizeof("./hello\n"), 1, fp);

    I got a new terminal, it opened like a file, fwrite() was also done but './hello' did not work like a command. It stood there like a dead text.

    Please help!!!!
    hii
    can you give the C code of ur problem so I can help u , and also I have same problem !!

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by CommonTater View Post
    C programs require compilation before they will run.
    Code:
    char r[40];
    sprintf(r,"gcc (options) %s\n", __FILE__);
    system(r);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. execute the run command from c program ...?
    By sma88 in forum C Programming
    Replies: 2
    Last Post: 02-22-2010, 09:35 AM
  2. Execute shell command from other user
    By LuckyStr in forum C++ Programming
    Replies: 12
    Last Post: 08-24-2009, 03:48 PM
  3. cout -> terminal command
    By Muscovy in forum Linux Programming
    Replies: 1
    Last Post: 07-04-2009, 03:50 AM
  4. How to execute a console command from your app?
    By GUIPenguin in forum C# Programming
    Replies: 2
    Last Post: 07-06-2006, 09:36 AM
  5. Execute Command from C fcn in DLL
    By karcheee in forum Windows Programming
    Replies: 2
    Last Post: 07-27-2005, 03:42 PM