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());

posted @ 2016-05-26 06:10  findumars  Views(5891)  Comments(1Edit  收藏  举报