Passing commands to standard In on windows (Mplayer related) [SOLVED]
-
wrote on 10 Sept 2014, 16:33 last edited by
Currently I have mplayer running in the background and would like to send it commands during runtime. I am aware that I will need to use slave mode (-slave). However I am not sure how I would pass these commands to standard in so that they can be read.
What I want to do is start mplayer and then at some point in time (when a button is pressed), pass it the file to play. However have no idea the best way to send commands to standard in from another program.
Currently what I think i'll have to do is somehow write to "cin" from inside the program so was thinking using ifstream to read from the file which contains commands written by ofstream. However this seems very messy so was wondering if anyone has an other ideas?
Does anyone have any useful information on where I go from here? I presuming I have to use some sort of Pipe but as this is my first jump into windows programming I am a bit lost. So any links or advice would be really helpful.
Thanks in advance
-
Hi,
That was for Linux but it's probably also applicable to Windows: use QProcess to start mplayer and communicate with it.
Hope it helps
-
wrote on 11 Sept 2014, 08:58 last edited by
Yea that is what I currently have, my program is launched with QProcess, however because this application is on windows I cannot just write to the file descriptor.
Otherwise I would do something like this:
@#include <unistd.h>
#include <string>
#include <sstream>
#include <iostream>
#include <thread>int main()
{
std::thread mess_with_stdin([] () {
for (int i = 0; i < 10; ++i) {
std::stringstream msg;
msg << "Self-message #" << i
<< ": Hello! How do you like that!?\n";
auto s = msg.str();
write(STDIN_FILENO, s.c_str(), s.size());
usleep(1000);
}
});std::string str; while (getline(std::cin, str)) std::cout << "String: " << str << std::endl; mess_with_stdin.join();
}@
What I am looking for is the process needed to do the same on windows as having trouble finding a solution to this problem. The problem is not with the QProcess side but the actual "Communication with it". Hopefully someone has used named pipes on windows might be able to point me in the right direction of a good tutorial.
-
QProcess is a QIODevice, so you can write there directly
-
wrote on 11 Sept 2014, 16:34 last edited by
Ledge Cheers didn't think to check if QProcess was capable of doing this also.
5/5