mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-23 22:20:24 -08:00
(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.
This commit is contained in:
parent
9d52160a5c
commit
d78e84f792
1 changed files with 15 additions and 4 deletions
|
|
@ -369,7 +369,7 @@ console_event_handler (DWORD event)
|
||||||
/* Change from normal usage; return value indicates whether spawn
|
/* Change from normal usage; return value indicates whether spawn
|
||||||
succeeded or failed - program return code is returned separately. */
|
succeeded or failed - program return code is returned separately. */
|
||||||
int
|
int
|
||||||
spawn (char * progname, char * cmdline, int * retcode)
|
spawn (char * progname, char * cmdline, char * dir, int * retcode)
|
||||||
{
|
{
|
||||||
BOOL success = FALSE;
|
BOOL success = FALSE;
|
||||||
SECURITY_ATTRIBUTES sec_attrs;
|
SECURITY_ATTRIBUTES sec_attrs;
|
||||||
|
|
@ -388,7 +388,7 @@ spawn (char * progname, char * cmdline, int * retcode)
|
||||||
start.cb = sizeof (start);
|
start.cb = sizeof (start);
|
||||||
|
|
||||||
if (CreateProcess (progname, cmdline, &sec_attrs, NULL, TRUE,
|
if (CreateProcess (progname, cmdline, &sec_attrs, NULL, TRUE,
|
||||||
0, envblock, NULL, &start, &child))
|
0, envblock, dir, &start, &child))
|
||||||
{
|
{
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
/* wait for completion and pass on return code */
|
/* wait for completion and pass on return code */
|
||||||
|
|
@ -432,12 +432,16 @@ main (int argc, char ** argv)
|
||||||
int num_pass_through_args;
|
int num_pass_through_args;
|
||||||
char modname[MAX_PATH];
|
char modname[MAX_PATH];
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
|
char dir[MAX_PATH];
|
||||||
|
|
||||||
|
|
||||||
interactive = TRUE;
|
interactive = TRUE;
|
||||||
|
|
||||||
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) console_event_handler, 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
|
/* 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),
|
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.
|
or in our role as a helper application for running DOS programs.
|
||||||
|
|
@ -453,6 +457,13 @@ main (int argc, char ** argv)
|
||||||
if (!GetModuleFileName (NULL, modname, sizeof (modname)))
|
if (!GetModuleFileName (NULL, modname, sizeof (modname)))
|
||||||
fail ("error: GetModuleFileName failed\n");
|
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
|
/* 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
|
might get run in other ways as well, so convert argv[0] to an
|
||||||
absolute name before comparing to the module name. */
|
absolute name before comparing to the module name. */
|
||||||
|
|
@ -462,7 +473,7 @@ main (int argc, char ** argv)
|
||||||
/* We are being used as a helper to run a DOS app; just pass
|
/* We are being used as a helper to run a DOS app; just pass
|
||||||
command line to DOS app without change. */
|
command line to DOS app without change. */
|
||||||
/* TODO: fill in progname. */
|
/* TODO: fill in progname. */
|
||||||
if (spawn (NULL, GetCommandLine (), &rc))
|
if (spawn (NULL, GetCommandLine (), dir, &rc))
|
||||||
return rc;
|
return rc;
|
||||||
fail ("Could not run %s\n", GetCommandLine ());
|
fail ("Could not run %s\n", GetCommandLine ());
|
||||||
}
|
}
|
||||||
|
|
@ -670,7 +681,7 @@ main (int argc, char ** argv)
|
||||||
if (!cmdline)
|
if (!cmdline)
|
||||||
cmdline = progname;
|
cmdline = progname;
|
||||||
|
|
||||||
if (spawn (progname, cmdline, &rc))
|
if (spawn (progname, cmdline, dir, &rc))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (!need_shell)
|
if (!need_shell)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue