function g_spawn_command_line_sync()
인수 "gchar **standard_output"
있습니다입심 - 2.0 : - g_spawn_command_line_sync() 알 수없는 표준 출력 길이
https://developer.gnome.org/glib/stable/glib-Spawning-Processes.html#g-spawn-command-line-sync
내가 standard_output에서 바이너리 데이터를 읽을 필요가 있지만, 나는하지 standard_output의 길이 알려져 있습니다.
http://fossies.org/dox/glib-2.38.2/gspawn-win32_8c_source.html#l01452
Function g_spawn_command_line_sync():
실행 :
GString *outstr = NULL;
*standard_output = g_string_free (outstr, FALSE);
Struct GString include "gsize len"
있지만 "gchar **"
접근 g_spawn_command_line_sync()
.
다음 해결책이 있습니다. 나는 사용하지 않는 size of stdout
을 stderr
에 기록한다.
예제 코드 :
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
int main()
{
gint exit_status = 0;
gchar *p_stdout = NULL;
gchar *p_stderr = NULL;
GError *p_error = NULL;
gboolean result;
result = g_spawn_command_line_sync("./make_image.py", &p_stdout, &p_stderr, &exit_status, &p_error);
if (!result) {
if (p_error != NULL) {
printf(p_error->message);
}
else {
printf("ERROR: Command not run\n");
}
}
else if (exit_status != 0) {
printf(p_stderr);
}
else {
int size = atoi(p_stderr);
gchar *p_c = p_stdout;
for (int i = 0; i < size; ++i) {
fputc(*p_c++, stdout);
}
//printf(p_stdout);
}
if (p_stdout) {
g_free(p_stdout);
}
if (p_stderr) {
g_free(p_stderr);
}
if (p_error) {
g_error_free(p_error);
}
return 0;
}