[Solved] QProcess
-
I would do the following:
don't call bash as the program you want to execute but directly "ls" with absolute path and arguments ">" & "output"
use the QProcess::waitForFinished() function to start the file reading
Here the code with the two modifications:
@QProcess process;
process.start("/usr/bin/ls", QStringList() << ">" << "Output.txt");
if(process.waitForFinished())
readfromProcess();@Does this solves your problem?
-
I have just tested the next code and it does the job correctly:
@
process.setStandardOutputFile("output.txt");
process.start("/bin/ls -lA");
process.waitForFinished();
@The command "ls < output.txt" doesn't work (I don't know why), that is why I call the function setStandardOutputFile().
-
Well, I don't actually have a working code for what I am trying to do yet. The problem with the < output.txt is the piping. < is a pipe and that is a separate process, so you need to create a second process to handle the piping... or more neatly as you did it. Once the ls program terminates, so does the thread or the process. That is also why starting bash and writing a pipe into it did work, because the process is running bash and doesn't terminate. So it can then it seems handle a piping within that thread or process. (at least that is what I have gathered, and filled in with my own imagination) I still have not gotten QStringList to work and I will most likely need it.
-
But, sorry I do not understand. The code I have posted above doesn't solve your problem? What do you need exactly?
By the way, this code with QStringList args also works:
@
process.setStandardOutputFile("output.txt");
process.start("/bin/ls", QStringList() << "-lA");
process.waitForFinished();
@ -
I see. I was looking at the arguments in the wrong framework I think. I am trying to add more commands or process'. I am trying to interface with namecoind daemon. So querying the namecoin database, and receiving Json objects. I do have the process working correctly now, thank you.
[code]
process.start("/usr/local/bin/namecoind", QStringList() << "name_show" << inputString);
[/code]