Windows and piped stdin...?

Jascha Wetzel "[firstname]" at mainia.de
Sun Feb 18 03:35:26 PST 2007


the problem appears to be in the c runtime that's used via std.c.stdio.
i worked around this by using win32 api directly:

/**
 * Wraps win32 stdio functions. Respects io redirection into pipes.
 */
class DbgIO
{
	static HANDLE ddb_read, ddb_write;
	static char[] buffer;

	static this()
	{
		ddb_read = GetStdHandle(STD_INPUT_HANDLE);
		ddb_write = GetStdHandle(STD_OUTPUT_HANDLE);
	}

	/**
	 *
	 */
	static char[] readln()
	{
		char[128] buf;
		uint read;

		int nl_index;
		do
		{
			ReadFile(ddb_read, buf.ptr, buf.length, &read, null);
			buffer ~= buf[0..read];
			nl_index = find(buffer, '\n');
		} while ( nl_index < 0 );
		char[] ret = buffer[0..nl_index];
		buffer = buffer[nl_index+1..$];
		return ret;
	}

	/**
	 *
	 */
	static void print(...)
	{
		char[] str;

		void putc(dchar c)
		{
			str ~= c;
		}

		doFormat(&putc, _arguments, _argptr);
		uint written;
		WriteFile(ddb_write, str.ptr, str.length, &written, null);
	}

	/**
	 *
	 */
	static void println(...)
	{
		char[] str;

		void putc(dchar c)
		{
			str ~= c;
		}

		doFormat(&putc, _arguments, _argptr);
		uint written;
		str ~= '\n';
		WriteFile(ddb_write, str.ptr, str.length, &written, null);
	}
}


alex wrote:
> No, sorry, it is NEVER working, not with "main.exe < input file" nor with just "main.exe" and putting some text manually in (end with ^Z).... It really seems that no EOF is sent on windows stdin....?
> 
> any ideas?
> 
> alex



More information about the Digitalmars-d mailing list