PDA

View Full Version : how to give exec command in the carbon c++ program?




chidambaram
Apr 12, 2008, 05:49 AM
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...........



robbieduncan
Apr 12, 2008, 05:54 AM
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?

chidambaram
Apr 12, 2008, 06:01 AM
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.

robbieduncan
Apr 12, 2008, 06:03 AM
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.

chidambaram
Apr 12, 2008, 06:06 AM
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.

robbieduncan
Apr 12, 2008, 06:14 AM
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.

chidambaram
Apr 12, 2008, 06:26 AM
ok sir.

Thanks for ur advice.

lee1210
Apr 12, 2008, 07:15 AM
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

cmaier
Apr 12, 2008, 09:29 AM
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.

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.