Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing commands to standard In on windows (Mplayer related) [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ion_knight
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ion_knight
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          QProcess is a QIODevice, so you can write there directly

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ion_knight
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved