CONTENTS | INDEX | PREV | NEXT
system
NAME
system - call system shell with command line
SYNOPSIS
#include <stdio.h>
#include <stdlib.h>
int r = system(buf);
const char *buf;
FUNCTION
system() calls the system shell with the specified command line,
returning the exit code of the command or -1 if it was unable to
run the command.
FOR PROGRAMS COMPILED UNDER 1.3, even if run in 1.4 enviroment, the
system call will not return the exit code from the command, but
return -1 if could not be run, 0 if it could.
FOR PROGRAMS COMPILED UNDER 2.0, system() will use the 2.0 calls
and return a proper exit code when running under 2.0, and will use
Execute() if running under 1.3
GETTING SYSTEM TO USE THE USER SHELL UNDER 2.0 (ADVANCED USERS ONLY)
Under 2.0 system() defaults to using the boot shell (i.e. commodore
shell). In order to have system() use the Sys_UserShell (for
example, to use WShell if you have WShell installed) you need to do
the following (usually in your main source module):
#include <dos/dostags.h>
int _SystemBoolTag = SYS_UserShell;
You could also set this global to SYS_CustomShell if you like. The
default value is TAG_IGNORE from <utility/tagitem.h>. To get even
more fancy you can also declare int _SystemBoolTagValue to modify
the data portion of the tag (default is 1).
Alternately you can simply #include <stdlib.h>, not declare either
variable explicitly (they are extern'd in <stdlib.h>), and modify
them run-time from main(). The compiler will thus give an error if
you make a mistake in the variable names.
EXAMPLE
#include <stdio.h>
#include <stdlib.h>
main()
{
char buf[256];
FILE *fi;
system("DIR >t:xx");
if (fi = fopen("t:xx", "r")) {
puts("Directory is:");
while (fgets(buf, sizeof(buf), fi))
printf("FuBarBletchPreamble: %s", buf);
fclose(fi);
remove("t:xx");
} else {
puts("Couldn't get directory!");
}
return(0);
}
INPUTS
char *buf; command line to run, like a normal AmigaDOS CLI command line.
RESULTS
int r; return code