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