Thread: Bash script in c

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    61

    Bash script in c

    Hi! I'm trying to call another c program via shell script in c, but it just pop-up and close again.. here's my code:

    Code:
    char* command = "";        
    char temp[MAX_LENGTH] = "";        
    
    sprintf(temp, "gnome-terminal -e 'bash -c \"./Isopropyl %s\"'", editor -> filename);
    command = malloc(strlen(temp) + 1);
            
    if(command == NULL)
         return;
    
    strcpy(command, temp);
    
    system(command);

    Edit: The title is incorrect I'm sorry, It should be "Shell script in c"
    Last edited by programmerc; 10-02-2014 at 07:21 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    You don't need any of that command stuff.

    You can just do system(temp); after the sprintf.

    You should also do
    printf("Cmd=%s\n", temp);
    as well, to verify what you're actually trying to pass off to gnome-terminal.

    You should also verify that Isopropyl is also in the current working directory.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exec a bash script
    By quo in forum Linux Programming
    Replies: 17
    Last Post: 06-02-2012, 06:01 AM
  2. Awk and sed bash script help
    By Annonymous in forum Linux Programming
    Replies: 19
    Last Post: 05-10-2012, 12:40 AM
  3. ssh/bash script question
    By Overworked_PhD in forum Tech Board
    Replies: 2
    Last Post: 03-30-2009, 07:48 PM
  4. Bash Script Q
    By QuestionC in forum Tech Board
    Replies: 1
    Last Post: 04-19-2007, 10:16 AM
  5. Linux: Use C to call a bash script
    By harada in forum Linux Programming
    Replies: 9
    Last Post: 10-27-2006, 01:59 PM