system() not working outside of Cygwin environment

Yuri Gribov tetra2005@googlemail.com
Mon Jan 16 04:21:00 GMT 2012


Hi all,

Perhaps this is very basic but I was not able to find the answer in faq/docs.

Attached is a nice small program which does system("cmd /?"); The call
works pretty well when I run it from Cygwin environment. In my
situation I need to run standalone Cygwin programs (i.e. simply from
Windows cmd.exe). In this case the program fails - system() does not
seem to find cmd.exe and returns -1 (yes, cygwin1.dll is on PATH). If
I change system() to good old CreateProcess() everything runs fine. My
questions:
1) what is the reason for this behavior?
2) can I somehow alter the argument to system() to make it working? Or
perhaps modify PATH or any other environment variable before running
Cygwin program?

Thanks in advance,
Yuri
-------------- next part --------------
#include <stdlib.h>
#include <stdio.h>

int main() {
	char tmp[256];
	getcwd(tmp, sizeof(tmp));
	printf("Cwd: %s\n", tmp);

	if( 0 != system("cmd /?") ) {
		printf("Failed\n");
	}

	return 0;
}

-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list