Skip to content

katahiromz/win_popen_bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Windows _popen bug found by @katahiromz

The following code works:

fp = _popen("cmdline.exe \"--test=TE ST\"", "rb"); /* SUCCESSFUL */
if (fp)
{
    while (fgets(buf, 256, fp))
    {
        fputs(buf, stdout);
    }
    _pclose(fp);
}
else
{
    fprintf(stderr, "ERROR: Cannot execute 'cmdline.exe'\n");
    return -1;
}

And then, the next code also works:

fp = _popen("\"cm dline.exe\" --test=TEST", "rb"); /* SUCCESSFUL */
if (fp)
{
    while (fgets(buf, 256, fp))
    {
        fputs(buf, stdout);
    }
    _pclose(fp);
}
else
{
    fprintf(stderr, "ERROR: Cannot execute 'cm dline.exe'\n");
    return -2;
}

But, the following code won't work:

fp = _popen("\"cm dline.exe\" \"--test=TE ST\"", "rb"); /* BUG: this is failed */
if (fp)
{
    while (fgets(buf, 256, fp))
    {
        fputs(buf, stdout);
    }
    _pclose(fp);
}
else
{
    fprintf(stderr, "ERROR: Cannot execute 'cm dline.exe'\n");
    return -3;
}

The screenshot