This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: an old problem with cygwin (fwd)


> Date: Thu, 08 Jan 2004 17:11:32 +0100 (MET)
> From: tekz@gmx.de
> To: m.buchmeier@fz-juelich.de
> Subject: an old problem with cygwin
> 
> On "http://www.cygwin.com/ml/cygwin/2001-11/msg00254.html"; you reported
> problems about running a cygwin bound program outside an "unix" shell:
> 
> > system() function doesnt work outside cygwin
> 
> So my answer is: It does work!
> But there are some conditions to provide the expected functionality:
> 
> You use the "C" function "system( .. )" to execute an external (shell)
> command.
> The following statements are true:
> a) the function is included through "<stdlib.h>"
> b) the function is part of "libc"
> c) the file "system.c" can be found in the "cygwin-libc" source tree
> d) the following function will be executed by a call to "system( .. )":
> 
> <code>
> static int
> do_system (ptr, s)
>      struct _reent *ptr;
>      _CONST char *s;
> {
>   char *argv[4];
>   int pid, status;
> 
>   argv[0] = "sh";
>   argv[1] = "-c";
>   argv[2] = (char *) s;
>   argv[3] = NULL;
> 
>   if ((pid = vfork ()) == 0)
>     {
>       /* ??? It's not clear what's the right path to take (pun intended :-).
> 	 There won't be an "sh" in any fixed location so we need each user
> 	 to be able to say where to find "sh".  That suggests using an
> 	 environment variable, but after a few more such situations we may
> 	 have too many of them.  */
>       char *sh = getenv ("SH_PATH");
>       if (sh == NULL)
> 	sh = "/bin/sh";
>       _execve (sh, argv, environ);
>       exit (100);
>     }
>   else if (pid == -1)
>     return -1;
>   else
>     {
>       int rc = _wait (&status);
>       if (rc == -1)
> 	return -1;
>       status = (status >> 8) & 0xff;
>       return status;
>     }
> }
> </code>
> 
> e) the function above executes the (shell) command through "sh"
> 
> conclusion: if you are trying to execute an external command from your
> cygwin bound program through
> a call to function "system( .. )" and the program "sh" ( "sh.exe" ) is not
> provided or can't be found in your standard windows search path than your
> program will and has to fail.
> 
> 
> thank you for reading this!
> One question arises: why does nobody explain this in the mailing list, news
> group or web ??
> 
> So, finally, my question to you is: did anybody help you by explaining
> something like this ??

My answer is no, noone was able to explain that i need the sh.exe
programm in my path. I also was not able find this info in the
documentation.
Finally David Mathog (mathog@caltech.edu) running into the same 
problem came to the conclusion that this behavior should be a bug, 
however i think there aws no reponse from the cygwin developpers 
and i didnt find the time to dig into the sources.

thankx for your explanation, i will try the solution out. 

				Matthias Buchmeier
				
###############################################
#         mail:  Matthias Buchmeier           #
#                IFF-IEE (Gruppe Gr"unberg)   #
#                Forschungszentrum J"ulich    #
#                52425 Juelich                #
#                Germany                      #
#                                             #
#           tel: +49 (0)2461 61 4273          #
#           fax:                4443          #
#         email: m.buchmeier@fz-juelich.de    #
###############################################



--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]