++RUN EXTERNAL PROGRAMS AS DOS RUNS EXTERNAL COMMAND:

View previous topic View next topic Go down

++RUN EXTERNAL PROGRAMS AS DOS RUNS EXTERNAL COMMAND:

Post  Admin on Fri Sep 19, 2008 2:34 am

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dir.h>
#include <process.h>
#define ALL_FILES_MASK 0x37

char buffer[256]="";

int Shell(char *EXE_DIR)
{
/*This routine first scans for the file name
exactly as it is given, then adds a .exe
extension, and finally adds a .com extension
if it still doesnt find a file it returns with 0*/

struct ffblk ffblk1;
int done=-1;
strcpy(buffer,EXE_DIR);
done=findfirst(buffer,&ffblk1,ALL_FILES_MASK);
if(!done) {
if(spawnl(P_WAIT,buffer,buffer,0,NULL)==-1)
perror("Error loading executable file");
return 1;
}
strcat(buffer,".EXE");
done=findfirst(buffer,&ffblk1,ALL_FILES_MASK);
if(!done) {
if(spawnl(P_WAIT,buffer,buffer,0,NULL)==-1)
perror("Error loading executable file");
return 1;
}
buffer[strlen(buffer)-4]='\0';
strcat(buffer,".COM");
done=findfirst(buffer,&ffblk1,ALL_FILES_MASK);
if(!done) {
if(spawnl(P_WAIT,buffer,buffer,0,NULL)==-1)
perror("Error loading executable file");
return 1;
}
return 0;
}

void main(void)
{
clrscr();
Shell("BGIDEMO");
}

This programs runs "BGIDEMO.EXE" from the working folder where this exe file situated if exist. But you can run any exe or com files through this Shell function. Try it and enjoy.
avatar
Admin
Admin

Posts : 256
Join date : 2008-06-06

View user profile http://debmedia.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum