Index: /trunk/src/corelib/io/qprocess_os2.cpp
===================================================================
--- /trunk/src/corelib/io/qprocess_os2.cpp	(revision 917)
+++ /trunk/src/corelib/io/qprocess_os2.cpp	(revision 918)
@@ -457,5 +457,5 @@
         // same pipe key may be mixed. We need CLOSE messages to be posted after
         // READ messages, so we do two passes.
-        
+
         // @todo We don't need two passes any more!
 
@@ -1087,13 +1087,14 @@
     q->setProcessState(QProcess::Starting);
 
-    APIRET arc;
+    int rc;
 
     QString error;
-    HFILE tmpStdin = HFILE(~0), tmpStdout = HFILE(~0), tmpStderr = HFILE(~0);
-    HFILE realStdin = HF_STDIN, realStdout = HF_STDOUT, realStderr = HF_STDERR;
+    int tmpStdin = -1, tmpStdout = -1, tmpStderr = -1;
+    int realStdin = fileno(stdin), realStdout = fileno(stdout),
+        realStderr = fileno(stderr);
 
     do {
         // save & copy the stdin handle
-        if ((arc = DosDupHandle(realStdin, &tmpStdin)) == NO_ERROR) {
+        if ((rc = tmpStdin = dup(realStdin)) != -1) {
             HFILE handle = stdinChannel.pipe.client;
             if (stdinChannel.type == Channel::PipeSink) {
@@ -1108,9 +1109,10 @@
                 Q_ASSERT(handle != HFILE(~0));
             }
-            arc = DosDupHandle(handle, &realStdin);
-        }
-        if (arc != NO_ERROR) {
-            DEBUG(("QProcessPrivate::startProcess: DosDupHandle for STDIN "
-                   "returned %lu", arc));
+            Q_ASSERT(_imphandle(handle) != -1);
+            rc = dup2(_imphandle(handle), realStdin);
+        }
+        if (rc == -1) {
+            DEBUG(("QProcessPrivate::startProcess: dup/dup2 for stdin "
+                   "failed with %d (%s)", errno, strerror(errno)));
             break;
         }
@@ -1118,5 +1120,5 @@
         if (processChannelMode != QProcess::ForwardedChannels) {
             // save & copy the stdout handle
-            if ((arc = DosDupHandle(realStdout, &tmpStdout)) == NO_ERROR) {
+            if ((rc = tmpStdout = dup(realStdout)) != -1) {
                 HFILE handle = stdoutChannel.pipe.client;
                 if (stdoutChannel.type == Channel::PipeSource) {
@@ -1131,21 +1133,27 @@
                     Q_ASSERT(handle != HFILE(~0));
                 }
-                arc = DosDupHandle(handle, &realStdout);
-            }
-            if (arc != NO_ERROR) {
-                DEBUG(("QProcessPrivate::startProcess: DosDupHandle for STDOUT "
-                       "returned %lu", arc));
+                Q_ASSERT(_imphandle(handle) != -1);
+                rc = dup2(_imphandle(handle), realStdout);
+            }
+            if (rc == -1) {
+                DEBUG(("QProcessPrivate::startProcess: dup/dup2 for stdout "
+                       "failed with %d (%s)", errno, strerror(errno)));
                 break;
             }
-            if ((arc = DosDupHandle(realStderr, &tmpStderr)) == NO_ERROR) {
+            if ((rc = tmpStderr = dup(realStderr)) != -1) {
                 // merge stdout and stderr if asked to
                 if (processChannelMode == QProcess::MergedChannels) {
-                    arc = DosDupHandle(realStdout, &realStderr);
+                    rc = dup2(realStdout, realStderr);
                 } else {
-                    arc = DosDupHandle(stderrChannel.pipe.client, &realStderr);
+                    HFILE handle = stderrChannel.pipe.client;
+                    Q_ASSERT(_imphandle(handle) != -1);
+                    rc = dup2(_imphandle(handle), realStderr);
                 }
             }
-            if (arc != NO_ERROR)
+            if (rc == -1) {
+                DEBUG(("QProcessPrivate::startProcess: dup/dup2 for stderr "
+                       "failed with %d (%s)", errno, strerror(errno)));
                 break;
+            }
         }
 
@@ -1153,5 +1161,5 @@
 
     int pid = -1;
-    if (arc == NO_ERROR) {
+    if (rc != -1) {
         QStringList env = environment.toStringList();
         pid = qt_startProcess(program, arguments, workingDirectory, &env);
@@ -1159,26 +1167,25 @@
 
     // cancel STDIN/OUT/ERR redirections
-    if (tmpStdin != HFILE(~0)) {
-        DosDupHandle(tmpStdin, &realStdin);
-        DosClose(tmpStdin);
-    }
-    if (tmpStdout != HFILE(~0)) {
-        DosDupHandle(tmpStdout, &realStdout);
-        DosClose(tmpStdout);
-    }
-    if ( tmpStderr != HFILE(~0)) {
-        DosDupHandle(tmpStderr, &realStderr);
-        DosClose(tmpStderr);
-    }
-
-    if (arc != NO_ERROR || pid == -1) {
+    if (tmpStdin != -1) {
+        dup2(tmpStdin, realStdin);
+        close(tmpStdin);
+    }
+    if (tmpStdout != -1) {
+        dup2(tmpStdout, realStdout);
+        close(tmpStdout);
+    }
+    if ( tmpStderr != -1) {
+        dup2(tmpStderr, realStderr);
+        close(tmpStderr);
+    }
+
+    if (rc == -1 || pid == -1) {
         // Cleanup, report error and return
         q->setProcessState(QProcess::NotRunning);
         processError = QProcess::FailedToStart;
-        if (arc != NO_ERROR) {
+        if (rc == -1) {
             // handle duplication failed
             q->setErrorString(QProcess::tr("Process failed to start: %1")
-                                           .arg(QString(QLatin1String("DOS error %1"))
-                                                .arg(arc)));
+                                           .arg(qt_error_string(errno)));
         } else {
             DEBUG(("spawnvpe failed: %s", qPrintable(qt_error_string(errno))));
