Subject: system() fails on pristine Windows systems
From: Archie Warnock <[email-masked]>
To: [email-masked]
Date: Mon, 25 Apr 2005 17:10:03 -0400

Hi all,

I've been through the FAQ and 2 years worth of archives, trying every
trick I could find there, but I cannot make this work.  I have a program
which calls Cygwin's system() function.  It works reliably from the
Windows command line (outside of Cygwin) on machines that have Cygwin
installed, even though the Cygwin bin-related directories are not in the
path.  It works on every single Unix machine I've ever tried it on.  It
fails reliably with the error message "No such file or directory" only
on Windows machines which do not have Cygwin installed.

To test that I haven't hosed anything up, I wrote a little demonstration
program which illustrates the problem:

+++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

int
main() {
  char foo[]="notepad";
  int ret;

  ret = system(foo);
  if (ret != 0) {
    fprintf(stderr,"Command failed: %s - %s\n",foo,strerror(errno));
  }
  exit(ret);
}
+++++++++++++++++++++++++++++++++++++++++++++++++++

If I build the exe file (with g++ - "g++ -o systest systest.cxx"), and
put both the exe file and cygwin1.dll on the non-Cygwin system, I get
the error (in this case, "Command failed: notepad.exe - No such file or
directory").  I've verified this behavior about 7 different Windows
machine with various flavors of Windows.

In addition, I've tried the various tricks - putting the directory
containing the exe file in the path (yes, before opening the cmd
window); putting cygwin1.dll in the \windows\system and
\windows\system32 directories; putting the Windows cmd.exe in the
directory with systest.exe; putting the Windows command.com in the
directory with systest.exe; even putting the Cygwin sh.exe in that
directory.  I have even tried replacing the call to run notepad.exe with
calls to do internal commands like "path" and "set" in Windows.  No joy...

It seems obvious to me that system() is not finding a command
interpreter on the machine, although they are correctly listed in the
path for the command window.  Am I missing something really stupid that
needs to be included in the distribution or set in the program, or does
system() just not work the way I expect?

Thanks in advance...

-- 
Archie

-- Archie Warnock                       Internet: [email-masked]
-- A/WWW Enterprises                    http://www.awcubed.com
--       As a matter of fact, I _do_ speak for my employer.

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