This is the mail archive of the
mailing list for the Cygwin project.
Re: system() not working outside of Cygwin environment
On Mon, Jan 16, 2012 at 08:21:21AM +0400, Yuri Gribov wrote:
>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
>1) what is the reason for this behavior?
If you google "system function linux", the first hit is a man page entry.
system() executes a command specified in command by calling /bin/sh -c
command, and returns after the command has been completed.
So, if /bin/sh is not available then system() won't work.
If you want to just execute a program the unix way is to use
Also note that if you are planning on making a program which is
distributed independent of Cygwin, your program must be distributed
under the terms of the GPL, i.e., you must make source code available.
Or, if you just want to write a program that starts another program you
might consider just using MinGW: http://mingw.org/ .
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple