8 #define SPAWN_BUFSIZE 128
10 gboolean spawn_sync(const char *working_directory,char **argv,
11 char **standard_output,int *exit_status,GError **error)
13 /* Don't use g_spawn_sync on WIN32 for now to avoid needing the helper */
15 char *standard_error=NULL;
17 GSpawnFlags flags=G_SPAWN_SEARCH_PATH;
19 flags=G_SPAWN_STDOUT_TO_DEV_NULL;
20 retval=g_spawn_sync(working_directory,argv,NULL,flags,NULL,NULL,
21 standard_output,&standard_error,exit_status,error);
23 g_printerr("%s",standard_error);
24 g_free(standard_error);
25 if (retval && exit_status)
26 *exit_status=WEXITSTATUS(*exit_status);
33 GString *command_line,*string;
34 if (working_directory)
36 current_dir=g_get_current_dir();
37 if (g_chdir(working_directory)<0)
39 g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
40 "%s: %s",working_directory,g_strerror(errno));
47 command_line=g_string_new(NULL);
51 g_string_append_c(command_line,' ');
52 g_string_append(command_line,argv[i]);
54 fp=popen(command_line->str,"r");
55 g_string_free(command_line,TRUE);
58 if (g_chdir(current_dir)<0)
59 g_error("Failed to restore current directory: %s",
65 g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
66 "%s: %s",command_line->str,g_strerror(errno));
69 string=g_string_new(NULL);
73 g_string_set_size(string,len+SPAWN_BUFSIZE);
74 n=fread(string->str+len,1,SPAWN_BUFSIZE,fp);
77 g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
78 "Error reading from bookloupe: %s",g_strerror(errno));
80 g_string_free(string,TRUE);
83 g_string_set_size(string,len+n);
88 g_set_error(error,G_FILE_ERROR,g_file_error_from_errno(errno),
89 "Error reading from bookloupe: %s",g_strerror(errno));
90 g_string_free(string,TRUE);
98 *standard_output=g_string_free(string,FALSE);
100 g_string_free(string,TRUE);