en***********@yahoo.com said:
Can anyone here please tell me how the system function is used to
execute DOS commands?
See comp.os.msdos.programmer for DOS-specific information, but the system()
part of your question is topical here.
Let us assume you have some system-specific command, FOO, which you wish to
execute with arguments bar and baz. Here is one simple way to do it:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int chomp(char *s)
{
char *p = NULL;
if(s != NULL)
{
p = strchr(s, '\n');
if(p != NULL)
{
*p = '\0';
}
}
return p != NULL;
}
int main(void)
{
char command[128] = "FOO ";
char argument[32] = {0};
if(system(NULL) == 0)
{
fputs("No command processor found!\n", stderr);
}
else
{
fputs("You are about to execute the FOO command,\n", stderr);
fputs("which takes two arguments. Please enter\n", stderr);
fputs("the first argument.\n", stderr);
if(fgets(argument, sizeof argument, stdin) != NULL)
{
if(chomp(argument))
{
strcat(command, argument);
strcat(command, " ");
fputs("Please enter the second argument.\n", stderr);
if(fgets(argument, sizeof argument, stdin) != NULL)
{
if(chomp(argument))
{
strcat(command, argument);
system(command);
}
else
{
fputs("Argument too long.\n", stderr);
}
}
}
else
{
fputs("Argument too long.\n", stderr);
}
}
else
{
fputs("Nothing to do.\n", stderr);
}
}
return 0;
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)