[PC-BSD Commits] r9460 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Wed Mar 2 07:02:54 PST 2011


Author: kenmoore
Date: 2011-03-02 07:02:54 -0800 (Wed, 02 Mar 2011)
New Revision: 9460

Modified:
   pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
   pcbsd/current/src-qt4/libpcbsd/utils.cpp
Log:
Added the new function QStringList Utils::runShellCommand(QString command)
This function runs the specified command and returns the screen output as a line-by-line list


Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2011-03-02 10:23:20 UTC (rev 9459)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2011-03-02 15:02:54 UTC (rev 9460)
@@ -53,6 +53,7 @@
    static bool setConfFileValue( QString oFile, QString oldKey, QString newKey, int occur );
    static QString getConfFileValue( QString oFile, QString Key );
    static QString getConfFileValue( QString oFile, QString Key, int occur );
+   static QStringList runShellCommand( QString command );
 };
 
 #endif

Modified: pcbsd/current/src-qt4/libpcbsd/utils.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/utils.cpp	2011-03-02 10:23:20 UTC (rev 9459)
+++ pcbsd/current/src-qt4/libpcbsd/utils.cpp	2011-03-02 15:02:54 UTC (rev 9460)
@@ -29,6 +29,7 @@
 #include <QStringList>
 #include <QFile>
 #include <QTextStream>
+#include <QProcess>
 
 #include "pcbsd-utils.h"
 
@@ -330,3 +331,14 @@
 	return true;
     
 }
+
+QStringList Utils::runShellCommand( QString command )
+{
+ QProcess p;
+ p.start(command);
+ p.waitForFinished(-1);
+ QString outstr = p.readAllStandardOutput();
+ if(outstr.endsWith("\n")){outstr.chop(1);} //remove the newline at the end 
+ QStringList out = outstr.split("\n"); //put each line into a different element
+ return out;
+}



More information about the Commits mailing list