qt執行cmd命令


源地址:http://blog.csdn.net/hn307165411/article/details/6858614

運行 route、ipconfig 肯定沒問題

Copy code
     QProcess p(0);
     p.start("route");
     p.waitForStarted();
     p.waitForFinished();
     qDebug()<<QString::fromLocal8Bit(p.readAllStandardError());



Copy code
     QProcess p(0);
     p.start("ipconfig");
     p.waitForStarted();
     p.waitForFinished();
     qDebug()<<QString::fromLocal8Bit(p.readAllStandardOutput());



而 dir 是命令行提供的命令,不是程序!

Copy code
     QProcess p(0);
     p.start("cmd");
     p.waitForStarted();
     p.write("dir\n");
     p.closeWriteChannel();
     p.waitForFinished();
     qDebug()<<QString::fromLocal8Bit(p.readAllStandardOutput());


Copy code
     QProcess p(0);
     p.start("cmd", QStringList()<<"/c"<<"dir");
     p.waitForStarted();
     p.waitForFinished();

     qDebug()<<QString::fromLocal8Bit(p.readAllStandardOutput());


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM