how to give exec command in the carbon c++ program?

Discussion in 'Mac Programming' started by chidambaram, Apr 12, 2008.

  1. macrumors member

    Joined:
    Mar 9, 2008
    #1
    hi all,

    I am working in a carbon c++ application using xcode.

    I am calling another program in my program.

    I used the exec command..

    my code is

    The prgram going to execute is
    /Users/laserwords/Desktop/Message_check/Carbon_ODBC_Example/main.c


    int main(int argc, char* argv[])

    {
    printf("\n I am main \n");
    IBNibRef nibRef;
    OSStatus err;
    }


    The program which call another program is


    void MainWindow::Starttheprocess()
    {
    printf("\n Execution starts \n ");
    char* param1;
    char* argv[1];
    exec("/Users/laserwords/Desktop/Message_check/Carbon_ODBC_Example/main.c",param1,argv, NULL);
    perror("execl");
    printf("\n Execution ends \n"); }
    }


    I got the error as "permission denied"

    What mistake i done here?

    Thanks in advance...........
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You are trying to execute a .c file? As in the non-executable source code? You realise you need to compile code before you can run it right?
     
  3. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #3
    yes i need the execute the c file.

    when i run that program individually it runs but when i given like this it shows this error.
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    You cannot execute a .c file. That is source code. Basically text. Text is not executable.

    Unless, of course, you have compiled the executable into a file with a .c extension. Which would be very unusual and weird.
     
  5. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #5
    sir,

    this c program is in the another carbon application.

    Without mentioning that c file, shall i mention that carbon application name.

    I created the executable file for that application.
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    The c file may be the source code for another carbon program but unless it has been compiled it is not executable. You do know the difference between source code and executable object code?

    Once again, you cannot execute C source code, usually and conventionally marked as a file with a .c extension.

    I sincerely suggest you do some very basic introduction to programming type courses.
     
  7. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #7
    ok sir.

    Thanks for ur advice.
     
  8. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #8
    I will make mention that the second program is going to replace the first completely. The running program, we'll call it program A, will cease to exist once the exec is called, and program B, the program referenced in the exec call, will take its place.

    This could be what you want to happen, but that is very rarely the case. Generally one wants to either fork then exec, which will set up Program B's process as a child of Program A, and they will continue executing simultaneously (unless the parent wait()'s for the child).

    Another common option is to simply use system() to start Program B. This basically sets up the fork/exec/wait in one call, and runs whatever programs or commands are passed via a shell.

    I just wanted to point this out as the current example seems unorthodox and likely not what you intend.

    -Lee
     
  9. macrumors G3

    Joined:
    Jul 25, 2007
    Location:
    California
    #9
    I don't want to be mean, but this guy has asked four questions that indicate very little understanding of general programming concepts (now add the object code versus source code confusion - can't get much more basic than knowing what a compiler/linker does). First, I think before you ask questions about every little thing you should try to educate yourself to at least a minimum level of understanding. But what makes all this seem really odd to me is the "urgent plz' at the end of most of his questions - how can it be urgent if he is asking this type of question? Is he employed somewhere (and completely unqualified?) Are we doing his homework for him? Something just feels wrong about all of this.
     

Share This Page