Mercurial > geeqie
comparison src/misc.c @ 1144:5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
author | zas_ |
---|---|
date | Sat, 15 Nov 2008 10:35:43 +0000 |
parents | 1646720364cf |
children | 3a0bb56adf8e |
comparison
equal
deleted
inserted
replaced
1143:893dfe1eca99 | 1144:5fe3b8b3a612 |
---|---|
184 g_free(e); | 184 g_free(e); |
185 return retval; | 185 return retval; |
186 } | 186 } |
187 return g_strdup("\"\""); | 187 return g_strdup("\"\""); |
188 } | 188 } |
189 | |
190 /* Run a command like system() but may output debug messages. */ | |
191 int runcmd(gchar *cmd) | |
192 { | |
193 #if 1 | |
194 return system(cmd); | |
195 return 0; | |
196 #else | |
197 /* For debugging purposes */ | |
198 int retval = -1; | |
199 FILE *in; | |
200 | |
201 DEBUG_1("Running command: %s", cmd); | |
202 | |
203 in = popen(cmd, "r"); | |
204 if (in) | |
205 { | |
206 int status; | |
207 const gchar *msg; | |
208 gchar buf[2048]; | |
209 | |
210 while (fgets(buf, sizeof(buf), in) != NULL ) | |
211 { | |
212 DEBUG_1("Output: %s", buf); | |
213 } | |
214 | |
215 status = pclose(in); | |
216 | |
217 if (WIFEXITED(status)) | |
218 { | |
219 msg = "Command terminated with exit code"; | |
220 retval = WEXITSTATUS(status); | |
221 } | |
222 else if (WIFSIGNALED(status)) | |
223 { | |
224 msg = "Command was killed by signal"; | |
225 retval = WTERMSIG(status); | |
226 } | |
227 else | |
228 { | |
229 msg = "pclose() returned"; | |
230 retval = status; | |
231 } | |
232 | |
233 DEBUG_1("%s : %d\n", msg, retval); | |
234 } | |
235 | |
236 return retval; | |
237 #endif | |
238 } | |
239 | |
240 | |
189 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ | 241 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |