PDA

Click to See Complete Forum and Search --> : Cmd.exe


TTAYO
September 17th, 2004, 11:05 PM
Hi there,

Please could someone tell me how I can execute/load a program from within a C program. What I really need is to be able to execute the C:\WINDOWS\SYSTEM32\CMD.exe executable from within a C program.

Any help would be greatly appreciated. :)

Thanx, in advance,
TTAYO

lepricaun
September 17th, 2004, 11:45 PM
using the system() function...

here's a program i'm working on, at the moment it works the same as the cmd.exe, check to see how it calls the commands:


#include <stdio.h>
#include <stdlib.h>
#include <strings.h>


int main(void)
{
char comm[200];
char cwd[100];
char dir[200];
int i,j;

while(1)
{
getcwd(cwd,100);
printf("\n%s>",cwd);
gets(comm);
if(strlen(comm)>199)
free(comm);
if(strcmp(comm,"exit")==0||strcmp(comm,"quit")==0)
{
free(comm);
free(cwd);
return EXIT_SUCCESS;
}
if(comm[0]=='c'&&comm[1]=='d'&&comm[2]==' ')
{
j=3;
for(i=0;i<strlen(comm);i++)
{
dir[i]=comm[j];
j++;
}
chdir(dir);
}
else
{
system(comm);
}
}
return EXIT_SUCCESS;
}


so if you would like to execute the cmd you could use the following code:

#include <stdio.h>

int main(void)
{
char *command="cmd.exe";
system(command);
return 0;
}



hope this helps ;)