src/corelib/io/qprocess.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
  1375     QProcessPrivate *dto = destination->d_func();
  1375     QProcessPrivate *dto = destination->d_func();
  1376     dfrom->stdoutChannel.pipeTo(dto);
  1376     dfrom->stdoutChannel.pipeTo(dto);
  1377     dto->stdinChannel.pipeFrom(dfrom);
  1377     dto->stdinChannel.pipeFrom(dfrom);
  1378 }
  1378 }
  1379 
  1379 
       
  1380 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
       
  1381 
       
  1382 /*!
       
  1383     \since 4.7
       
  1384 
       
  1385     Returns the additional native command line arguments for the program.
       
  1386 
       
  1387     \note This function is available only on the Windows and Symbian
       
  1388     platforms.
       
  1389 
       
  1390     \sa setNativeArguments()
       
  1391 */
       
  1392 QString QProcess::nativeArguments() const
       
  1393 {
       
  1394     Q_D(const QProcess);
       
  1395     return d->nativeArguments;
       
  1396 }
       
  1397 
       
  1398 /*!
       
  1399     \since 4.7
       
  1400     \overload
       
  1401 
       
  1402     Sets additional native command line \a arguments for the program.
       
  1403 
       
  1404     On operating systems where the system API for passing command line
       
  1405     \a arguments to a subprocess natively uses a single string, one can
       
  1406     conceive command lines which cannot be passed via QProcess's portable
       
  1407     list-based API. In such cases this function must be used to set a
       
  1408     string which is \e appended to the string composed from the usual
       
  1409     argument list, with a delimiting space.
       
  1410 
       
  1411     \note This function is available only on the Windows and Symbian
       
  1412     platforms.
       
  1413 
       
  1414     \sa nativeArguments()
       
  1415 */
       
  1416 void QProcess::setNativeArguments(const QString &arguments)
       
  1417 {
       
  1418     Q_D(QProcess);
       
  1419     d->nativeArguments = arguments;
       
  1420 }
       
  1421 
       
  1422 #endif
       
  1423 
  1380 /*!
  1424 /*!
  1381     If QProcess has been assigned a working directory, this function returns
  1425     If QProcess has been assigned a working directory, this function returns
  1382     the working directory that the QProcess will enter before the program has
  1426     the working directory that the QProcess will enter before the program has
  1383     started. Otherwise, (i.e., no directory has been assigned,) an empty
  1427     started. Otherwise, (i.e., no directory has been assigned,) an empty
  1384     string is returned, and QProcess will use the application's current
  1428     string is returned, and QProcess will use the application's current
  1854     setReadChannel(tmp);
  1898     setReadChannel(tmp);
  1855     return data;
  1899     return data;
  1856 }
  1900 }
  1857 
  1901 
  1858 /*!
  1902 /*!
  1859     Starts the program \a program in a new process, if one is not already
  1903     Starts the given \a program in a new process, if none is already
  1860     running, passing the command line arguments in \a arguments. The OpenMode
  1904     running, passing the command line arguments in \a arguments. The OpenMode
  1861     is set to \a mode.
  1905     is set to \a mode.
  1862 
  1906 
  1863     The QProcess object will immediately enter the Starting state. If the
  1907     The QProcess object will immediately enter the Starting state. If the
  1864     process starts successfully, QProcess will emit started(); otherwise,
  1908     process starts successfully, QProcess will emit started(); otherwise,
  1865     error() will be emitted. If the QProcess object is already running a
  1909     error() will be emitted. If the QProcess object is already running a
  1866     process, a warning may be printed at the console, and the existing
  1910     process, a warning may be printed at the console, and the existing
  1867     process will continue running.
  1911     process will continue running.
  1868 
  1912 
  1869     \note Arguments that contain spaces are not passed to the
       
  1870     process as separate arguments.
       
  1871 
       
  1872     \note Processes are started asynchronously, which means the started()
  1913     \note Processes are started asynchronously, which means the started()
  1873     and error() signals may be delayed. Call waitForStarted() to make
  1914     and error() signals may be delayed. Call waitForStarted() to make
  1874     sure the process has started (or has failed to start) and those signals
  1915     sure the process has started (or has failed to start) and those signals
  1875     have been emitted.
  1916     have been emitted.
       
  1917 
       
  1918     \note No further splitting of the arguments is performed.
  1876 
  1919 
  1877     \bold{Windows:} Arguments that contain spaces are wrapped in quotes.
  1920     \bold{Windows:} Arguments that contain spaces are wrapped in quotes.
  1878 
  1921 
  1879     \sa pid(), started(), waitForStarted()
  1922     \sa pid(), started(), waitForStarted()
  1880 */
  1923 */
  2077     Starts the program \a program with the arguments \a arguments in a
  2120     Starts the program \a program with the arguments \a arguments in a
  2078     new process, waits for it to finish, and then returns the exit
  2121     new process, waits for it to finish, and then returns the exit
  2079     code of the process. Any data the new process writes to the
  2122     code of the process. Any data the new process writes to the
  2080     console is forwarded to the calling process.
  2123     console is forwarded to the calling process.
  2081 
  2124 
  2082     The environment and working directory are inherited by the calling
  2125     The environment and working directory are inherited from the calling
  2083     process.
  2126     process.
  2084 
  2127 
  2085     On Windows, arguments that contain spaces are wrapped in quotes.
  2128     On Windows, arguments that contain spaces are wrapped in quotes.
       
  2129 
       
  2130     If the process cannot be started, -2 is returned. If the process
       
  2131     crashes, -1 is returned. Otherwise, the process' exit code is
       
  2132     returned.
  2086 */
  2133 */
  2087 int QProcess::execute(const QString &program, const QStringList &arguments)
  2134 int QProcess::execute(const QString &program, const QStringList &arguments)
  2088 {
  2135 {
  2089     QProcess process;
  2136     QProcess process;
  2090     process.setReadChannelMode(ForwardedChannels);
  2137     process.setReadChannelMode(ForwardedChannels);
  2091     process.start(program, arguments);
  2138     process.start(program, arguments);
  2092     process.waitForFinished(-1);
  2139     if (!process.waitForFinished(-1))
  2093     return process.exitCode();
  2140         return -2;
       
  2141     return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
  2094 }
  2142 }
  2095 
  2143 
  2096 /*!
  2144 /*!
  2097     \overload
  2145     \overload
  2098 
  2146 
  2103 int QProcess::execute(const QString &program)
  2151 int QProcess::execute(const QString &program)
  2104 {
  2152 {
  2105     QProcess process;
  2153     QProcess process;
  2106     process.setReadChannelMode(ForwardedChannels);
  2154     process.setReadChannelMode(ForwardedChannels);
  2107     process.start(program);
  2155     process.start(program);
  2108     process.waitForFinished(-1);
  2156     if (!process.waitForFinished(-1))
  2109     return process.exitCode();
  2157         return -2;
       
  2158     return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
  2110 }
  2159 }
  2111 
  2160 
  2112 /*!
  2161 /*!
  2113     Starts the program \a program with the arguments \a arguments in a
  2162     Starts the program \a program with the arguments \a arguments in a
  2114     new process, and detaches from it. Returns true on success;
  2163     new process, and detaches from it. Returns true on success;