Running GREP from QProcess (pyqt4)
I just can't get this to run correctly. I am trying to run the grep via QProcess, as follows:
self.process = QtCore.QProcess()
self.arguments_test = QtCore.QStringList()
self.arguments_test << "-rn" << "hello" << "/home/user/*";
I get : <PyQt4.QtCore.QStringList object at 0xb4776df4>
I've tried running simpler commands such as ls, with parameters too and it works.
Thanks in advance.
QProcess won't do shell wildcard expansion for you. Invoke a shell (sh -c or such) to perform that.
Thanks for replying. So, do you have any basic code sample for invoking the shell? What is the class I should be looking at?
QProcess is the right class :) you just need to invoke a shell to perform that wildcard expansion.
options << "-c" << "grep -rn hello /tmp/*";
I will try that! thanks a lot for your help.
Hi dangelog your code works perfectly.A ton of thaks to you.But i am searching for a way to provide the search pattern name in a variable so that the user can give any pattern to search
QString pattern = "hello";
options << "-c" << "grep -r -w -i -o -c "<<pattern<<" hello /tmp/* ";