....forwarded to the calling process.??
-
@JonB RTFM??
nt QProcess::execute(const QString &program, const QStringList &arguments)
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.@AnneRanch said in ....forwarded to the calling process.??:
@JonB RTFM??
I beg your pardon?
I explained it is a
staticfunction. I explained it means that writingQP->execute()does not openQP, and that is why your output showsQIODevice::read (QProcess): device not openerror.
For your purpose here it is much simpler to use
QProcess::start().QProcess::execute()offers you no advantage over that, only makes life harder. Up to you. Earlier on @ChrisW67 showed code if you really want to useexecute()[though I have to say, I did not find it worked correctly at least in Qt 5.15, Ubuntu], his later post shows usingstart(). Also withexecute()you will never have the option of being able to connect signals. -
@AnneRanch said in ....forwarded to the calling process.??:
@JonB RTFM??
I beg your pardon?
I explained it is a
staticfunction. I explained it means that writingQP->execute()does not openQP, and that is why your output showsQIODevice::read (QProcess): device not openerror.
For your purpose here it is much simpler to use
QProcess::start().QProcess::execute()offers you no advantage over that, only makes life harder. Up to you. Earlier on @ChrisW67 showed code if you really want to useexecute()[though I have to say, I did not find it worked correctly at least in Qt 5.15, Ubuntu], his later post shows usingstart(). Also withexecute()you will never have the option of being able to connect signals.@JonB before somebody posts another example how to modify a+b to b+a
kindly please provide reference to correct this official QT document when STATIC is implemented .RTFM and note that "execute" is referenced under "static".
nt QProcess::execute(const QString &program, const QStringList &arguments)
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.To the contributors whose code "waits for finish " - please note the above highlighted part.
I appreciate all constructive contributions, however, somehow the original post OBJECTIVE to discuss how data is forwarded to calling process is being masked by usual personal innuendos ( format your code ,,, we told you so ... etc) .
PLEASE stop that. -
@JonB before somebody posts another example how to modify a+b to b+a
kindly please provide reference to correct this official QT document when STATIC is implemented .RTFM and note that "execute" is referenced under "static".
nt QProcess::execute(const QString &program, const QStringList &arguments)
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.To the contributors whose code "waits for finish " - please note the above highlighted part.
I appreciate all constructive contributions, however, somehow the original post OBJECTIVE to discuss how data is forwarded to calling process is being masked by usual personal innuendos ( format your code ,,, we told you so ... etc) .
PLEASE stop that.@AnneRanch said in ....forwarded to the calling process.??:
how data is forwarded to calling process
What exactly do you want to know here? How it's done internally so you can read it with the functions fomr QProcess? If not - what else?
-
@JonB before somebody posts another example how to modify a+b to b+a
kindly please provide reference to correct this official QT document when STATIC is implemented .RTFM and note that "execute" is referenced under "static".
nt QProcess::execute(const QString &program, const QStringList &arguments)
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.To the contributors whose code "waits for finish " - please note the above highlighted part.
I appreciate all constructive contributions, however, somehow the original post OBJECTIVE to discuss how data is forwarded to calling process is being masked by usual personal innuendos ( format your code ,,, we told you so ... etc) .
PLEASE stop that.@AnneRanch said in ....forwarded to the calling process.??:
kindly please provide reference to correct this official QT document when STATIC is implemented .
Kindly note that I did precisely that in the post you are asking about
int QProcess::execute(const QString &program, const QStringList &arguments = {}) is
staticThat's what I wrote. It has the link to the documentation. Is that what you wanted that you're not happy with? Or something else?
RTFM and note that "execute" is referenced under "static".
I do "RTFM", thank you very much.
- If you use
QProcess::execute()you will find it difficult to get any output correctly/reliably. IMHO. - If you use
QProcess::start()plus some kind ofQProcess::waitForFinished()you will be able to useQProcess::read...()to read the output from the spawned process.
Why not just try saying "thank you"? That would be really nice. Or something without the "F" in it when people try to help you?
- If you use
-
@AnneRanch said in ....forwarded to the calling process.??:
kindly please provide reference to correct this official QT document when STATIC is implemented .
Kindly note that I did precisely that in the post you are asking about
int QProcess::execute(const QString &program, const QStringList &arguments = {}) is
staticThat's what I wrote. It has the link to the documentation. Is that what you wanted that you're not happy with? Or something else?
RTFM and note that "execute" is referenced under "static".
I do "RTFM", thank you very much.
- If you use
QProcess::execute()you will find it difficult to get any output correctly/reliably. IMHO. - If you use
QProcess::start()plus some kind ofQProcess::waitForFinished()you will be able to useQProcess::read...()to read the output from the spawned process.
Why not just try saying "thank you"? That would be really nice. Or something without the "F" in it when people try to help you?
I LIKE TO KNOW WHY THIS DOES NOT WORK WHEN USED A STATIC.....
'WHERE DOES IT SAY THAT IN THIS SNIPPET OF OFFICIAL DOCUMENTATION
?????
?
/
PLEASE
no more personal remarks / opinions why it should not be used as STATIC .....
'
PLEASE
pay attention to highlighted part which was the original subject if my post and is continually derailed by opinions....int QProcess::execute(const QString &program, const QStringList &arguments = {})
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.
The environment and working directory are inherited from the calling process.
Argument handling is identical to the respective start() overload.
If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process' exit code is returned.
See also start().
- If you use
-
I LIKE TO KNOW WHY THIS DOES NOT WORK WHEN USED A STATIC.....
'WHERE DOES IT SAY THAT IN THIS SNIPPET OF OFFICIAL DOCUMENTATION
?????
?
/
PLEASE
no more personal remarks / opinions why it should not be used as STATIC .....
'
PLEASE
pay attention to highlighted part which was the original subject if my post and is continually derailed by opinions....int QProcess::execute(const QString &program, const QStringList &arguments = {})
Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.
The environment and working directory are inherited from the calling process.
Argument handling is identical to the respective start() overload.
If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process' exit code is returned.
See also start().
@AnneRanch said in ....forwarded to the calling process.??:
no more personal remarks / opinions why it should not be used as STATIC .....
When you write:
QProcess *QP = new QProcess(); QP->execute(command); qDebug() << QP->readAllStandardOutput();it won't work because
QProcess::execute()is astaticmethod. You will get nothing back, and an error message from the last line saying theQProcessis not open. Astaticmethod does not operate on any instance you happen to call it on. The code above is really:QProcess *QP = new QProcess(); QProcess::execute(command); qDebug() << QP->readAllStandardOutput();You can see the
QPinstance has not been used to open or execute the command. You cannot read from it.QProcess::execute()has its own internalQProcessinstance it creates and destroys, you cannot access it.That is how
staticclass methods work in C++. -
As mentioned above using a static method means you don't get an instance of the class that you can use non-static methods on. That means if you run
QProcess::executeit internally creates a QProcess instance that you don't get access to. This means you can't useQProcess::readAllStandardOutputbecause that is not a static method and you don't have access to an instance you can call it on. If you create another instance they don't share the output.Calling static method on a non-static object (so
QP->execute) is just something that C++ lets you do, but it's just syntax sugar over static call and it has nothing to do with the QP instance. Those are not QProcess or Qt topics. That's just how static functions work in C++.All that doesn't mean documentation is wrong. With the static
QProcess::executea stream forwarding is used, meaning that if the subprocess writes to the output, e.g. withstd::cout << "hello"the calling process catches it and puts it into its own output stream, so you will see it in the output stream of the calling process. If you want to catch it to, for example, put it in a textbox or something, you can do it but it's quite complicated.
First you need to do standard cout and cerr stream redirection. I'm not gonna go into detail because there's enough materials out there and it's not Qt specific topic.
Second, becauseQProcess::executeis a blocking call you probably will have to start another thread to read that output in realtime, or better yet start thatQProcess::executein another thread so it doesn't block your UI.
Third, even if you redirect cout to some sort of handler of yours that subprocess output will be mixed with that of the calling process and you'll have to do some parsing to differentiate which part of the output is from which process.So that being said static
QProcess::executeis not a good choice for the task of reading the output of the called process. It can be done if someone is stubborn enough, but it requires a lot of pointless work that can be replaced with just a few lines of creating a QProcess instance, callingstart,waitForFinishedandreadAllStandardOutput.QProcess::executeis a convenience shortcut for cases when you don't need to interact with the process you're calling.The documentation is ok, just doesn't go into details where the streams are redirected, because it's not really meant to be used this way. If you want then you have to do some digging on stream redirection yourself, but that's really self inflicted pain that is not necessary.
-
Life is too short. Once again we have the "I'll delete all my posts" response.
Wow, who would be so rude/ungrateful after everybody has posted so much in response trying to help as to delete all their posts?!
Long time ago I posted a reply on a similar toplc and got a toxic answer.
Once bitten twice shy...You are right! I keep forgetting this, thinking it will be better and would be nice to help someone. I need to take the "bitten" ["mauled"? ;-) ] lesson to heart!
-
I've restored them so we can refer to them when the same question is asked in two weeks again.