comparison src/callproc.c @ 13719:660032b84b23

(Fcall_process) [MSDOS]: Support redirection of stderr. Assign process exit code to `synch_process_retcode' and error description to `synch_process_death'. Reset `synch_process_alive' to zero when the sub-process exits.
author Karl Heuer <kwzh@gnu.org>
date Wed, 13 Dec 1995 02:26:40 +0000
parents b435aa964922
children 621a575db6f7
comparison
equal deleted inserted replaced
13718:e1b33f87545f 13719:660032b84b23
322 } 322 }
323 new_argv[i - 3] = 0; 323 new_argv[i - 3] = 0;
324 } 324 }
325 325
326 #ifdef MSDOS /* MW, July 1993 */ 326 #ifdef MSDOS /* MW, July 1993 */
327 /* These vars record information from process termination.
328 Clear them now before process can possibly terminate,
329 to avoid timing error if process terminates soon. */
330 synch_process_death = 0;
331 synch_process_retcode = 0;
332
333 if ((outf = egetenv ("TMP")) || (outf = egetenv ("TEMP"))) 327 if ((outf = egetenv ("TMP")) || (outf = egetenv ("TEMP")))
334 strcpy (tempfile = alloca (strlen (outf) + 20), outf); 328 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
335 else 329 else
336 { 330 {
337 tempfile = alloca (20); 331 tempfile = alloca (20);
347 if (outfilefd < 0) 341 if (outfilefd < 0)
348 { 342 {
349 close (filefd); 343 close (filefd);
350 report_file_error ("Opening process output file", Fcons (tempfile, Qnil)); 344 report_file_error ("Opening process output file", Fcons (tempfile, Qnil));
351 } 345 }
346 fd[1] = outfilefd;
352 #endif 347 #endif
353 348
354 if (INTEGERP (buffer)) 349 if (INTEGERP (buffer))
355 fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1; 350 fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1;
356 else 351 else
385 /* These vars record information from process termination. 380 /* These vars record information from process termination.
386 Clear them now before process can possibly terminate, 381 Clear them now before process can possibly terminate,
387 to avoid timing error if process terminates soon. */ 382 to avoid timing error if process terminates soon. */
388 synch_process_death = 0; 383 synch_process_death = 0;
389 synch_process_retcode = 0; 384 synch_process_retcode = 0;
390
391 #ifdef MSDOS /* MW, July 1993 */
392 /* ??? Someone who knows MSDOG needs to check whether this properly
393 closes all descriptors that it opens. */
394 pid = run_msdos_command (new_argv, current_dir, filefd, outfilefd);
395 close (outfilefd);
396 fd1 = -1; /* No harm in closing that one! */
397 fd[0] = open (tempfile, NILP (Vbinary_process_output) ? O_TEXT : O_BINARY);
398 if (fd[0] < 0)
399 {
400 unlink (tempfile);
401 close (filefd);
402 report_file_error ("Cannot re-open temporary file", Qnil);
403 }
404 #else /* not MSDOS */
405 385
406 if (NILP (error_file)) 386 if (NILP (error_file))
407 fd_error = open (NULL_DEVICE, O_WRONLY); 387 fd_error = open (NULL_DEVICE, O_WRONLY);
408 else if (STRINGP (error_file)) 388 else if (STRINGP (error_file))
409 { 389 {
422 close (fd[0]); 402 close (fd[0]);
423 if (fd1 >= 0) 403 if (fd1 >= 0)
424 close (fd1); 404 close (fd1);
425 report_file_error ("Cannot open", error_file); 405 report_file_error ("Cannot open", error_file);
426 } 406 }
427 407 #ifdef MSDOS /* MW, July 1993 */
408 /* ??? Someone who knows MSDOG needs to check whether this properly
409 closes all descriptors that it opens.
410
411 Note that run_msdos_command() actually returns the child process
412 exit status, not its PID, so we assign it to `synch_process_retcode'
413 below. */
414 pid = run_msdos_command (new_argv, current_dir,
415 filefd, outfilefd, fd_error);
416
417 /* Record that the synchronous process exited and note its
418 termination status. */
419 synch_process_alive = 0;
420 synch_process_retcode = pid;
421 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
422 synch_process_death = strerror(errno);
423
424 close (outfilefd);
425 if (fd_error != outfilefd)
426 close (fd_error);
427 fd1 = -1; /* No harm in closing that one! */
428 fd[0] = open (tempfile, NILP (Vbinary_process_output) ? O_TEXT : O_BINARY);
429 if (fd[0] < 0)
430 {
431 unlink (tempfile);
432 close (filefd);
433 report_file_error ("Cannot re-open temporary file", Qnil);
434 }
435 #else /* not MSDOS */
428 #ifdef WINDOWSNT 436 #ifdef WINDOWSNT
429 pid = child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir); 437 pid = child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir);
430 #else /* not WINDOWSNT */ 438 #else /* not WINDOWSNT */
431 pid = vfork (); 439 pid = vfork ();
432 440
439 #else 447 #else
440 setpgrp (pid, pid); 448 setpgrp (pid, pid);
441 #endif /* USG */ 449 #endif /* USG */
442 child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir); 450 child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir);
443 } 451 }
452 #endif /* not WINDOWSNT */
444 #endif /* not MSDOS */ 453 #endif /* not MSDOS */
445 #endif /* not WINDOWSNT */
446 454
447 environ = save_environ; 455 environ = save_environ;
448 456
449 /* Close most of our fd's, but not fd[0] 457 /* Close most of our fd's, but not fd[0]
450 since we will use that to read input from. */ 458 since we will use that to read input from. */