delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
X-SWARE-Spam-Status: | No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE |
X-Spam-Check-By: | sourceware.org |
X-Mail-Handler: | MailHop Outbound by DynDNS |
X-Report-Abuse-To: | abuse AT dyndns DOT com (see http://www.dyndns.com/services/mailhop/outbound_abuse.html for abuse reporting information) |
X-MHO-User: | U2FsdGVkX1/C7dqi3S+zujD9K29mnrwu |
Date: | Mon, 16 Jan 2012 00:05:10 -0500 |
From: | Christopher Faylor <cgf-use-the-mailinglist-please AT cygwin DOT com> |
To: | cygwin AT cygwin DOT com |
Subject: | Re: system() not working outside of Cygwin environment |
Message-ID: | <20120116050510.GC12205@ednor.casa.cgf.cx> |
Reply-To: | cygwin AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
References: | <CAJOtW+6mu8JDmyBsXGbWc_emnVRJMuJDSC7W4jzPPWwan3xp+g AT mail DOT gmail DOT com> |
MIME-Version: | 1.0 |
In-Reply-To: | <CAJOtW+6mu8JDmyBsXGbWc_emnVRJMuJDSC7W4jzPPWwan3xp+g@mail.gmail.com> |
User-Agent: | Mutt/1.5.20 (2009-06-14) |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Unsubscribe: | <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
On Mon, Jan 16, 2012 at 08:21:21AM +0400, Yuri Gribov wrote: >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? If you google "system function linux", the first hit is a man page entry. It explains: Description 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 fork()/exec(). 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/ . cgf -- 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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |