diff --git a/System/Process/Internals.hs b/System/Process/Internals.hs
index c805ad0e2adaf2b015dad403ebf780f5207f742d..2286d31adb1a88f7d26c3b1144a93a29361272ad 100644
--- a/System/Process/Internals.hs
+++ b/System/Process/Internals.hs
@@ -417,12 +417,17 @@ pfdToHandle pfd mode = do
                        False {-is_socket-}
                        False {-non-blocking-}
   fD <- FD.setNonBlockingMode fD True -- see #3316
-  mkHandleFromFD fD fd_type filepath mode False{-is_socket-}
-                       (Just localeEncoding)
+  enc <- getLocaleEncoding
+  mkHandleFromFD fD fd_type filepath mode False {-is_socket-} (Just enc)
 #else
   fdToHandle' fd (Just Stream)
-     False{-Windows: not a socket,  Unix: don't set non-blocking-}
-     filepath mode True{-binary-}
+     False {-Windows: not a socket,  Unix: don't set non-blocking-}
+     filepath mode True {-binary-}
+#endif
+
+#if __GLASGOW_HASKELL__ < 703
+getLocaleEncoding :: IO TextEncoding
+getLocaleEncoding = return localEncoding
 #endif
 
 #ifndef __HUGS__