0

In a GThread I have code as such

char *commandLine [1024];
sprintf(commandLine, "gcc myfile.c -o myfile.exe 2>&1");

FILE*           pipein_fp;
extern FILE*    popen();
static char     buffer [1024];

pipein_fp = popen(commandLine, "r");
while(fgets(buffer, 1024, pipein_fp) != NULL) g_print("\n%s", buffer);
pclose(pipein_fp);

so 2>&1 is supposed to redirect stderr to stdout and the piped g_print is supposed to print out the gcc's stderr output. But it does nothing. What am I possibly doing wrong ?

Imobilis
  • 1,475
  • 8
  • 29
  • 2
    Are you sure the program has errors? If there are no errors, it won't print anything to stderr. – Barmar Jun 06 '16 at 07:06

1 Answers1

2

Your code has an error, Please change

char *commandLine [1024];
sprintf(commandLine, "gcc myfile.c -o myfile.exe 2>&1");

to

char commandLine [1024];
sprintf(commandLine, "gcc myfile.c -o myfile.exe 2>&1");

For sprintf, the first parameter is char* str.

You can read how to control popen stdin, stdout, stderr redirection?

Community
  • 1
  • 1
BlackMamba
  • 10,054
  • 7
  • 44
  • 67
  • I didn't copy that part and decided to write it on-hand here. This is how this mistake was born, but it's too late to edit it anyway. I upvoted though I can't submit it as solution, because I am too idiotic and the code I was compiling wasn't bad. – Imobilis Jun 06 '16 at 12:50