Unsolved how to pipe qprocess' stdout to father process as stdin
-
@jsulm Because libmpv only support passing filename string or "-" that means read from stdin...
-
@Isolde said in how to pipe qprocess' stdout to father process as stdin:
So I want to start streamlink inside my program and pipe its stdout into my-qt-program's stdin. Is it possible?
That's why I wrote earlier "but I don't know how easy/possible to connect that to parent's stdin". Neither I nor seemingly @jsulm know how to change a running Qt program's stdin.
You may safely assume that the
QProcess
approach is not going to work in the running parent program. One can guess that this refers to only a "sub-process", not the current process. I know what sort of code they will have written for the redirection, and they will be offering it only as they start a sub-process. What you need is a "redirect current stdin" call, and I don't see Qt offering that.If you are Linux only, I can tell you how to do it in C, which will presumably be reflected in C++, or you could look that up. I think it will "work" in that Qt's stdin will reflect the change, but you would not be doing the redirection or the sub-process spawning as Qt calls. Which may not be attractive.
Alternatively you can write simple shell scripts as a "wrapper" when launching your Qt application. You could even write another small Qt application to invoke your current Qt application in the right way if you prefer!
-
Hi,
As already suggested, you can use QProcess and its channels communication API to process the output of mpv within your application. From the looks of it, there's no need for piping anything.
-
@SGaist But what I want is to input data into libmpv...
-
@JNBarchan Thank you for your patient help, I'll write a shell script to wrap them.
-
@Isolde
I do think if you can manage with that it will be a lot simpler than trying to do it from Qt.Now that I have understood your objective, I will say that there is nothing wrong about it as a desired facility in Qt. However, so far as I can see (and I have Googled a lot) Qt does not offer any means of redirecting a parent process's (not
QProcess
) own stdin/stdout/stderr from/to a piped child process, and that is actually a lacking feature in its otherwise comprehensive library. -
@JNBarchan I found a workaround.
Now I usingQProcess
'sstartDetached()
likeQProcess* restart; restart = new QProcess; restart->startDetached("bash -c \"streamlink -O | my-qt-program \""); exit(0);
It works well!
-
@Isolde
Yes, you mean, you have written that as a second Qt application which does this to invoke your original Qt application, instead of a script file. Which is what we were suggesting :) [EDIT: Or, do you mean you actually do this from within your original "my-qt-program"?] -
@JNBarchan said in how to pipe qprocess' stdout to father process as stdin:
Or, do you mean you actually do this from within your original "my-qt-program
That would be an endless loop :-)
-
@JNBarchan said in how to pipe qprocess' stdout to father process as stdin:
is
Not quite. I just add a simple if statement that determine whether to execute this restart code like
if(QCoreApplication::arguments().at(1) != "bypass-parser") { QProcess* restart; restart = new QProcess; restart->startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " + QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\""); exit(0); }
-
@jsulm I'm sorry. They are not the whole codes, I post them completely in the last reply.
-
@Isolde You should not exit a Qt app like this, use http://doc.qt.io/qt-5/qcoreapplication.html#exit instead. Also there is no need to allocate QProcess on the heap. And in this particular case there is even no need for a QProcess instance at all as startDetached is static:
if(QCoreApplication::arguments().at(1) != "bypass-parser") { QProcess::startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " + QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\""); QCoreApplication::exit(0); }
-
@jsulm Got it. I'll amend it. Thank you very much.
-
@jsulm said in how to pipe qprocess' stdout to father process as stdin:
@JNBarchan said in how to pipe qprocess' stdout to father process as stdin:
Or, do you mean you actually do this from within your original "my-qt-program
That would be an endless loop :-)
That's why I asked, and he has posted to show how he detects....
-
@jsulm said in how to pipe qprocess' stdout to father process as stdin:
@Isolde You should not exit a Qt app like this, use http://doc.qt.io/qt-5/qcoreapplication.html#exit instead. Also there is no need to allocate QProcess on the heap. And in this particular case there is even no need for a QProcess instance at all as startDetached is static:
if(QCoreApplication::arguments().at(1) != "bypass-parser") { QProcess::startDetached("bash -c \"streamlink " + parser.value(urlOption) + " " + parser.value(streamOption) + " -O | " + QCoreApplication::applicationFilePath() + " bypass-parser " + parser.value(urlOption) + "\""); QCoreApplication::exit(0); }
There is a strange problem, my program won't exit with
QCoreApplication::exit(0);
(but it could exit normally withexit(0)
), I saw two windows withQCoreApplication::exit(0);
. And the terminal output indicated that the old process had run into the GUI drawing step. -
So you want to control mpv from your application ?