[Mono-devel-list] [PATCH] detect a stdin/out/err redirection (Isatty)

Wojciech Polak polak at gnu.org
Mon Nov 10 07:23:21 EST 2003


Hello,

I wanted to detect a standard input/output/error redirection,
but couldn't find a proper solution in C#, so I added the `isatty'
syscall to Mono.Posix. I hope this is the right place for that.
This patch (attached) is for the current CVS. Of course, beside
a common syscall, I wrote the specific Isatty(), which returns
a boolean value. I tested it with the following example and it
works good ($mcs -r:Mono.Posix.dll example.cs):

using System;
using Mono.Posix;

class Test
{
	public static void Main ()
	{
		if (!Syscall.Isatty (0x00000000))
			Console.WriteLine ("Stdin redirected");

		if (!Syscall.Isatty (0x00000001))
			Console.WriteLine ("Stdout redirected");
	}
}

Unfortunately, I couldn't figure out how to use the Wrapper.cs
from corlib/Unix/, so I tested it with 0x00000000 and 0x00000001,
and anyway it works okay.

I look forward to seeing any kind of `isatty' implementation
in Mono.

Regards,
Wojciech
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Syscall-Isatty.diff
Type: application/octet-stream
Size: 761 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20031110/eafbeae8/attachment.obj 


More information about the Mono-devel-list mailing list