++RUN EXTERNAL PROGRAMS AS DOS RUNS EXTERNAL COMMAND:
Page 1 of 1
++RUN EXTERNAL PROGRAMS AS DOS RUNS EXTERNAL COMMAND:
#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.
#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.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum