Passing commands to standard In on windows (Mplayer related) [SOLVED]

  • 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

  • Lifetime Qt Champion


    That was for Linux but it's probably also applicable to Windows: use QProcess to start mplayer and communicate with it.

    Hope it helps

  • 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());

    std::string str;
    while (getline(std::cin, str))
        std::cout << "String: " << str << std::endl;


    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.

  • Lifetime Qt Champion

    QProcess is a QIODevice, so you can write there directly

  • Ledge Cheers didn't think to check if QProcess was capable of doing this also.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.