Bug 14422 – std.process: Pipes do not append to files on Win64
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2015-04-07T11:50:00Z
Last change time
2017-07-19T17:43:01Z
Keywords
pull
Assigned to
nobody
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2015-04-07T11:50:37Z
//////////////////////////// test.d ///////////////////////////
import std.process;
import std.stdio;
import std.file;
void main()
{
auto fn = "fn.txt";
std.file.write(fn, "AAAAAAAAAA");
auto f = File(fn, "a");
spawnProcess(["cmd", "/c", "echo BBBBB"], stdin, f).wait();
auto data = readText(fn);
assert(data == "AAAAAAAAAABBBBB\r\n", data);
}
///////////////////////////////////////////////////////////////
This program runs fine on Win32, but the assert fails on Win64.
For some reason, the "a" mode is being ignored, and the content is written to the beginning of the file, clobbering the original file header.
Comment #1 by dlang-bugzilla — 2015-04-07T12:15:57Z
C program which reproduces this bug:
/////////////////////// ctest.c ///////////////////////
#include <stdio.h>
#include <windows.h>
void main()
{
FILE *f;
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {sizeof(STARTUPINFO)};
f = fopen("test.txt", "w");
fprintf(f, "AAAAAAAAAA\n");
fclose(f);
f = fopen("test.txt", "a");
si.hStdOutput = (HANDLE)_get_osfhandle(_fileno(f));
si.dwFlags = STARTF_USESTDHANDLES;
CreateProcess(NULL, "cmd /c \"echo BBBBB\"",
NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
}
///////////////////////////////////////////////////////
Comment #2 by dlang-bugzilla — 2015-04-07T12:29:06Z