According to the POSIX specs, the system() function should have the same effect as sh -c "...". Apparently this is not the case.
$ sh -c 'set -x; (echo abc)'
+ echo abc
abc
$ ./system-test.exe 'set -x; (echo abc)'
Executing set -x; (echo abc) ...
Environment variable -x; (echo abc) not defined
See also http://www.opengroup.org/onlinepubs/000095399/functions/system.html for more information.
Setup details:
Host OS: Windows 7, 32-bit.
gcc version:
$ gcc -v
Reading specs from c:/mingw/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)
$ ld -v
GNU ld (GNU Binutils) 2.20.51.20100613
Version of mingwrt: 3.18
Test program source code.
Yes, Windows is not POSIX compliant. Windows never said that it was. MinGW uses the MSVCRT runtime. You must do as Windows does. Check MSDN for the documentation for the use of the system() function.
Thanks for the feedback.