[GRASS-dev] Exit code for Tk GUI

Maris Nartiss maris.gis at gmail.com
Mon Sep 24 09:36:08 EDT 2007


2007/9/24, Glynn Clements <glynn at gclements.plus.com>:
>
> G_gui() can call exit() with the value returned from pclose(); it
> doesn't have to return to the caller. See my patch.
>
Sorry. I really misread Your patch.
Just for record if somebody is going to use it - correct way is like this:

--- lib/gis/parser.c	8 Sep 2007 16:22:21 -0000	1.130
+++ lib/gis/parser.c	24 Sep 2007 13:20:36 -0000
@@ -81,6 +81,8 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
 #include <grass/spawn.h>
@@ -1887,6 +1889,7 @@
 static void G_gui_tcltk (void)
 {
 	FILE *fp;
+	int status;

 	if (!pgm_name)
 		pgm_name = G_program_name ();
@@ -1912,7 +1915,10 @@

 	generate_tcl(fp);

-	pclose(fp);
+	status = pclose(fp);
+	if (status < 0)
+		G_fatal_error("error while executing 'wish'");
+	exit(WEXITSTATUS(status));
 }

 /* Build wxPython gui */

>
> If you're running the command manually from the command line, you
> probably aren't paying any attention to exit codes. If you're running
> it from a script, you're likely to be providing arguments.
>
Probably reporter has some use case where GUI's returned exit code has
some use otherwise there would be no bugreport about this.

TCL's close{} provides error code from launched module in "proc
Gronsole::readeof" IF in "proc Gronsole::execbg " pipeline is not
changed to be non-blocking (remove "fconfigure $fh -blocking 0").

wbr,
Maris.




More information about the grass-dev mailing list