I use system() command in Qt. and I want to get output and show it to users. my command is:
system("echo '" + rootPass.toAscii() + "' | su - root -c 'yum -y install " + packageName.toAscii() + "'");
this command can't run when I use it in QProcess (start or execute function)
but if i can run this command in QProcess i can get output with QProcess::readAllStandardOutput()
function.
also when i used ">" in system command to save output in a file, I receive output when the package completely installed. like bellow:
system("echo '" + rootPass.toAscii() + "' | su - root -c 'yum -y install " + packageName.toAscii() + "' > result.out");
is there any idea about running this command with QProcess, or get output from system() command as soon as write each line.
system("echo '" + rootPass. toAscii() + "' | su - root -c 'yum -y install " + packageName. toAscii() + "' > result. out");
There is a Arguments line edit where you can put all you need to pass to your app when launching it. For Qt Creator from Qt 5.6 Go in the "Projects part on the left and then in the "Build & Run" tab. Here you have a "Command line arguments" edit where you can put all parameters you want to pass to your app.
@grullo said in Run command line from Qt app in linux: QString cmdline = ". /home/grullo/xmip-bundle/build/xmipp. bashrc"; I guess the initial dot (".") is making your command line relative, so that path is not found when set the working directory.
You can also obtain the output directly from QProcess
QProcess process;
process.start(/* command line stuff */);
process.waitForFinished(-1); // will wait forever until finished
QString stdout = process.readAllStandardOutput();
QString stderr = process.readAllStandardError();
If you don't want to block your event loop, you can always use the signals:
readyReadStandardOutput();
readyReadStandardError();
And then call a function to readAllStandard[Output/Error]
What you want to execute is a shell command. You need to pass it to a shell. Run the following command using QProcess:
/bin/bash -c "your_command | with_pipes > and_redirects"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With