Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chidambaram

macrumors member
Original poster
Mar 9, 2008
67
0
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors member
Original poster
Mar 9, 2008
67
0
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors member
Original poster
Mar 9, 2008
67
0
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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

Suspended
Jul 25, 2007
25,405
33,474
California
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.