Turns out I made example code for someone in the nsis IRC channel a long time ago to handle this
Comparing Instructor's code with mine and my notes, you should call GetStdHandle first, then AttachConsole, and use the built in FileWrite command and not WriteConsole, if you do this, you can use pipes and redirection (foo.exe > out.txt etc.) still limited to XP and up
so, without any error handling or anything:
PHP Code:
System::Call 'kernel32::GetStdHandle(i -11)i.r0'
System::Call 'kernel32::AttachConsole(i -1)'
FileWrite $0 "hello"