Index: src/org/jruby/ext/posix/POSIXFactory.java =================================================================== --- src/org/jruby/ext/posix/POSIXFactory.java (revision 213) +++ src/org/jruby/ext/posix/POSIXFactory.java (working copy) @@ -87,7 +87,7 @@ Map options = new HashMap(); options.put(com.sun.jna.Library.OPTION_FUNCTION_MAPPER, new WindowsLibCFunctionMapper()); - return new WindowsPOSIX(name, loadLibC(name, LibC.class, options), handler); + return new WindowsPOSIX(name, loadLibC(name, WindowsLibC.class, options), handler); } public static LibC loadLibC(String libraryName, Class libCClass, Map options) { Index: src/org/jruby/ext/posix/WindowsLibCFunctionMapper.java =================================================================== --- src/org/jruby/ext/posix/WindowsLibCFunctionMapper.java (revision 213) +++ src/org/jruby/ext/posix/WindowsLibCFunctionMapper.java (working copy) @@ -23,6 +23,7 @@ methodNameMap.put("stat", "_stat64"); methodNameMap.put("mkdir", "_mkdir"); methodNameMap.put("umask", "_umask"); + methodNameMap.put("isatty", "_isatty"); } public String getFunctionName(NativeLibrary library, Method method) { Index: src/org/jruby/ext/posix/JavaLibCHelper.java =================================================================== --- src/org/jruby/ext/posix/JavaLibCHelper.java (revision 213) +++ src/org/jruby/ext/posix/JavaLibCHelper.java (working copy) @@ -53,11 +53,14 @@ public static final int STDERR = 2; POSIXHandler handler; - Field field; + Field fdField, handleField; public JavaLibCHelper(POSIXHandler handler) { this.handler = handler; - this.field = FieldAccess.getProtectedField(FileDescriptor.class, "fd"); + this.handleField = FieldAccess.getProtectedField(FileDescriptor.class, + "handle"); + this.fdField = FieldAccess.getProtectedField(FileDescriptor.class, + "fd"); } public int chmod(String filename, int mode) { @@ -78,10 +81,9 @@ } public int getfd(FileDescriptor descriptor) { - if (descriptor == null || field == null) return -1; - + if (descriptor == null || fdField == null) return -1; try { - return field.getInt(descriptor); + return fdField.getInt(descriptor); } catch (SecurityException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { @@ -90,6 +92,18 @@ return -1; } + public long gethandle(FileDescriptor descriptor) { + if (descriptor == null || handleField == null) return -1; + try { + return handleField.getLong(descriptor); + } catch (SecurityException e) { + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } + + return -1; + } + public String getlogin() { return System.getProperty("user.name"); } Index: src/org/jruby/ext/posix/WindowsPOSIX.java =================================================================== --- src/org/jruby/ext/posix/WindowsPOSIX.java (revision 213) +++ src/org/jruby/ext/posix/WindowsPOSIX.java (working copy) @@ -220,8 +220,8 @@ @Override public boolean isatty(FileDescriptor fd) { - return (fd == FileDescriptor.in - || fd == FileDescriptor.out - || fd == FileDescriptor.err); + int handle = (int)helper.gethandle(fd); + int crtfd = ((WindowsLibC)libc)._open_osfhandle(handle, 0/*_O_RDONLY*/); + return libc.isatty(crtfd) != 0; } } Index: src/org/jruby/ext/posix/WindowsLibC.java =================================================================== --- src/org/jruby/ext/posix/WindowsLibC.java (revision 213) +++ src/org/jruby/ext/posix/WindowsLibC.java (working copy) @@ -1,4 +1,5 @@ package org.jruby.ext.posix; -public interface WindowsLibC extends POSIX { +public interface WindowsLibC extends LibC { + public int _open_osfhandle(int handle, int flags); }