changeset 23947:f01d27883cb1

(spawn): Pass directory for child as parameter. (main): Save startup directory to give to spawn, then change directory to location of .exe in order not to prevent startup directory from being deleted.
author Andrew Innes <andrewi@gnu.org>
date Mon, 28 Dec 1998 19:25:28 +0000
parents 82f89865fa9b
children 5d7a43e8b133
files nt/cmdproxy.c
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/nt/cmdproxy.c	Mon Dec 28 10:10:22 1998 +0000
+++ b/nt/cmdproxy.c	Mon Dec 28 19:25:28 1998 +0000
@@ -369,7 +369,7 @@
 /* Change from normal usage; return value indicates whether spawn
    succeeded or failed - program return code is returned separately.  */
 int
-spawn (char * progname, char * cmdline, int * retcode)
+spawn (char * progname, char * cmdline, char * dir, int * retcode)
 {
   BOOL success = FALSE;
   SECURITY_ATTRIBUTES sec_attrs;
@@ -388,7 +388,7 @@
   start.cb = sizeof (start);
 
   if (CreateProcess (progname, cmdline, &sec_attrs, NULL, TRUE,
-		     0, envblock, NULL, &start, &child))
+		     0, envblock, dir, &start, &child))
   {
     success = TRUE;
     /* wait for completion and pass on return code */
@@ -432,12 +432,16 @@
   int num_pass_through_args;
   char modname[MAX_PATH];
   char path[MAX_PATH];
+  char dir[MAX_PATH];
 
 
   interactive = TRUE;
 
   SetConsoleCtrlHandler ((PHANDLER_ROUTINE) console_event_handler, TRUE);
 
+  if (!GetCurrentDirectory (sizeof (dir), dir))
+    fail ("error: GetCurrentDirectory failed\n");
+
   /* We serve double duty: we can be called either as a proxy for the
      real shell (that is, because we are defined to be the user shell),
      or in our role as a helper application for running DOS programs.
@@ -453,6 +457,13 @@
   if (!GetModuleFileName (NULL, modname, sizeof (modname)))
     fail ("error: GetModuleFileName failed\n");
 
+  /* Change directory to location of .exe so startup directory can be
+     deleted.  */
+  progname = strrchr (modname, '\\');
+  *progname = '\0';
+  SetCurrentDirectory (modname);
+  *progname = '\\';
+
   /* Although Emacs always sets argv[0] to an absolute pathname, we
      might get run in other ways as well, so convert argv[0] to an
      absolute name before comparing to the module name.  */
@@ -462,7 +473,7 @@
       /* We are being used as a helper to run a DOS app; just pass
 	 command line to DOS app without change.  */
       /* TODO: fill in progname.  */
-      if (spawn (NULL, GetCommandLine (), &rc))
+      if (spawn (NULL, GetCommandLine (), dir, &rc))
 	return rc;
       fail ("Could not run %s\n", GetCommandLine ());
     }
@@ -670,7 +681,7 @@
   if (!cmdline)
     cmdline = progname;
 
-  if (spawn (progname, cmdline, &rc))
+  if (spawn (progname, cmdline, dir, &rc))
     return rc;
 
   if (!need_shell)