Changeset 918
- Timestamp:
- Jul 31, 2011, 8:41:23 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/corelib/io/qprocess_os2.cpp
r913 r918 457 457 // same pipe key may be mixed. We need CLOSE messages to be posted after 458 458 // READ messages, so we do two passes. 459 459 460 460 // @todo We don't need two passes any more! 461 461 … … 1087 1087 q->setProcessState(QProcess::Starting); 1088 1088 1089 APIRET arc;1089 rc; 1090 1090 1091 1091 QString error; 1092 HFILE tmpStdin = HFILE(~0), tmpStdout = HFILE(~0), tmpStderr = HFILE(~0); 1093 HFILE realStdin = HF_STDIN, realStdout = HF_STDOUT, realStderr = HF_STDERR; 1092 int tmpStdin = -1, tmpStdout = -1, tmpStderr = -1; 1093 int realStdin = fileno(stdin), realStdout = fileno(stdout), 1094 realStderr = fileno(stderr); 1094 1095 1095 1096 do { 1096 1097 // save & copy the stdin handle 1097 if (( arc = DosDupHandle(realStdin, &tmpStdin)) == NO_ERROR) {1098 if (() { 1098 1099 HFILE handle = stdinChannel.pipe.client; 1099 1100 if (stdinChannel.type == Channel::PipeSink) { … … 1108 1109 Q_ASSERT(handle != HFILE(~0)); 1109 1110 } 1110 arc = DosDupHandle(handle, &realStdin); 1111 } 1112 if (arc != NO_ERROR) { 1113 DEBUG(("QProcessPrivate::startProcess: DosDupHandle for STDIN " 1114 "returned %lu", arc)); 1111 Q_ASSERT(_imphandle(handle) != -1); 1112 rc = dup2(_imphandle(handle), realStdin); 1113 } 1114 if (rc == -1) { 1115 DEBUG(("QProcessPrivate::startProcess: dup/dup2 for stdin " 1116 "failed with %d (%s)", errno, strerror(errno))); 1115 1117 break; 1116 1118 } … … 1118 1120 if (processChannelMode != QProcess::ForwardedChannels) { 1119 1121 // save & copy the stdout handle 1120 if (( arc = DosDupHandle(realStdout, &tmpStdout)) == NO_ERROR) {1122 if (() { 1121 1123 HFILE handle = stdoutChannel.pipe.client; 1122 1124 if (stdoutChannel.type == Channel::PipeSource) { … … 1131 1133 Q_ASSERT(handle != HFILE(~0)); 1132 1134 } 1133 arc = DosDupHandle(handle, &realStdout); 1134 } 1135 if (arc != NO_ERROR) { 1136 DEBUG(("QProcessPrivate::startProcess: DosDupHandle for STDOUT " 1137 "returned %lu", arc)); 1135 Q_ASSERT(_imphandle(handle) != -1); 1136 rc = dup2(_imphandle(handle), realStdout); 1137 } 1138 if (rc == -1) { 1139 DEBUG(("QProcessPrivate::startProcess: dup/dup2 for stdout " 1140 "failed with %d (%s)", errno, strerror(errno))); 1138 1141 break; 1139 1142 } 1140 if (( arc = DosDupHandle(realStderr, &tmpStderr)) == NO_ERROR) {1143 if (() { 1141 1144 // merge stdout and stderr if asked to 1142 1145 if (processChannelMode == QProcess::MergedChannels) { 1143 arc = DosDupHandle(realStdout, &realStderr);1146 realStderr); 1144 1147 } else { 1145 arc = DosDupHandle(stderrChannel.pipe.client, &realStderr); 1148 HFILE handle = stderrChannel.pipe.client; 1149 Q_ASSERT(_imphandle(handle) != -1); 1150 rc = dup2(_imphandle(handle), realStderr); 1146 1151 } 1147 1152 } 1148 if (arc != NO_ERROR) 1153 if (rc == -1) { 1154 DEBUG(("QProcessPrivate::startProcess: dup/dup2 for stderr " 1155 "failed with %d (%s)", errno, strerror(errno))); 1149 1156 break; 1157 1150 1158 } 1151 1159 … … 1153 1161 1154 1162 int pid = -1; 1155 if ( arc == NO_ERROR) {1163 if () { 1156 1164 QStringList env = environment.toStringList(); 1157 1165 pid = qt_startProcess(program, arguments, workingDirectory, &env); … … 1159 1167 1160 1168 // cancel STDIN/OUT/ERR redirections 1161 if (tmpStdin != HFILE(~0)) {1162 DosDupHandle(tmpStdin, &realStdin);1163 DosClose(tmpStdin);1164 } 1165 if (tmpStdout != HFILE(~0)) {1166 DosDupHandle(tmpStdout, &realStdout);1167 DosClose(tmpStdout);1168 } 1169 if ( tmpStderr != HFILE(~0)) {1170 DosDupHandle(tmpStderr, &realStderr);1171 DosClose(tmpStderr);1172 } 1173 1174 if ( arc != NO_ERROR|| pid == -1) {1169 if (tmpStdin != ) { 1170 realStdin); 1171 lose(tmpStdin); 1172 } 1173 if (tmpStdout != ) { 1174 realStdout); 1175 lose(tmpStdout); 1176 } 1177 if ( tmpStderr != ) { 1178 realStderr); 1179 lose(tmpStderr); 1180 } 1181 1182 if ( || pid == -1) { 1175 1183 // Cleanup, report error and return 1176 1184 q->setProcessState(QProcess::NotRunning); 1177 1185 processError = QProcess::FailedToStart; 1178 if ( arc != NO_ERROR) {1186 if () { 1179 1187 // handle duplication failed 1180 1188 q->setErrorString(QProcess::tr("Process failed to start: %1") 1181 .arg(QString(QLatin1String("DOS error %1")) 1182 .arg(arc))); 1189 .arg(qt_error_string(errno))); 1183 1190 } else { 1184 1191 DEBUG(("spawnvpe failed: %s", qPrintable(qt_error_string(errno))));
Note:
See TracChangeset
for help on using the changeset viewer.