QProcess uses old arguments for new QProcess

  • So I have this code which just returns 1 AUR helper from an ls call but had to call bash first to get the pipes working.

    void Worker::getAURHelper(bool konsoleFlag, bool aur)
    	qDebug() << "get aur helper called";
    	//searches /usr/bin for AUR helpers and returns the first entry without trailing \n
    	QProcess *getAURHelperProcess = new QProcess(this);
    	QStringList AURHelperArguments;
    	AURHelperArguments << "-c" << "/usr/bin/ls /usr/bin/ | egrep -w '(apacman|aura|aurget|bauerbill|burgaur|pacaur|pacget|packer|pkgbuilder|spinach|trizen|wrapaur|yaourt|yay)' | head -n1 | tr -d '\n'";
    	getAURHelperProcess->start("/usr/bin/bash", AURHelperArguments);
    	if (getAURHelperProcess->waitForStarted(3000))
    		qDebug() << "get aur helper started" << endl;
    		if (getAURHelperProcess->waitForReadyRead(-1))
    			if (getAURHelperProcess->waitForFinished())
    				QString AURHelper = getAURHelperProcess->readAllStandardOutput();
    				qDebug()<< "AUR HELPER" << AURHelper;
    				emit Worker::upgradeSystem(konsoleFlag, aur, AURHelper);
    				qDebug() << "cannot finish";
    			qDebug() << "cannot read from get aur helper";
    		qDebug() << "cannot start getAURHelper";

    It emits a signal and my problem is that the old process arguments are bleeding into the new call.

    int Worker::upgradeSystem(bool konsoleFlag, bool aur, QString AURHelper)
    	QProcess *systemUpdateProcess = new QProcess(this);
    	if (aur && konsoleFlag == false)
    		QStringList arguments;
    		//start with aur helper add aur helper specific commands
     		QStringList AURCommands = getAURHelperCommands(AURHelper);
    		for (int i = 0; i < AURCommands.size(); i++)
     			arguments << AURCommands[i];
    // 		}
    		systemUpdateProcess->start("pkexec", arguments);

    It ends up calling pkexec on the command from getAURHelper even though it finished

    any advice?

  • Lifetime Qt Champion


    What is the content of AUREhelper ?

    What do you expect it to be ?

    By the way you should rather allocate your QProcess objects on the stack or delete them when your done with them. Giving them a parent will only ensure they are properly destroyed when the parent is destroyed.

  • I think I figured it out.

    calling bash is a dirty hack that is causing the entire issue. when I call anything other than bash it doesnt happen.

    the proper way is to call .setStandardOutputProcess

    from stack overflow

    QProcess process1;
    QProcess process2;
    process1.start("cat file");
    process2.start("grep string");

    also thanks for the calling on stack tip

  • well i was wrong that didnt work

  • It's weird it happens with .start but not with .execute.

    I know why it because .start is asynchronous while .execute is synchronous

    I think I just need to run a Regex out .readAllStanardOutput from the QT side of things versus chaining shells

  • back to square one.

    just going to use QDIr library

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.