3 /* system( const char * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
11 /* This is an example implementation of system() fit for use with POSIX kernels.
14 extern int fork( void );
15 extern int execve( const char * filename, char * const argv[], char * const envp[] );
16 extern int wait( int * status );
18 int system( const char * string )
20 char const * const argv[] = { "sh", "-c", (char const * const)string, NULL };
26 execve( "/bin/sh", (char * * const)argv, NULL );
30 while( wait( NULL ) != pid );
37 #include <_PDCLIB_test.h>
39 #define SHELLCOMMAND "echo 'SUCCESS testing system()'"
46 TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
47 TESTCASE( system( SHELLCOMMAND ) );
49 TESTCASE( fread( buffer, 1, 24, fh ) == 24 );
50 TESTCASE( memcmp( buffer, "SUCCESS testing system()", 24 ) == 0 );
51 TESTCASE( buffer[24] == 'x' );
52 TESTCASE( fclose( fh ) == 0 );
53 TESTCASE( remove( testfile ) == 0 );