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. [SOLVED] How to send Standard input to a QProcess or use piping

[SOLVED] How to send Standard input to a QProcess or use piping

Scheduled Pinned Locked Moved General and Desktop
mplayer2standard inputqprocesspipingmplayerinteractive inp
3 Posts 2 Posters 12.8k Views
  • 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.
  • P Offline
    P Offline
    Poulad
    wrote on last edited by Poulad
    #1

    hi folks

    Is it possible to send standard input to a QProcess? like piping in GNU/Linux.

    I ran mplayer2 using:

      QProcess *process = new QProcess();
      process->start("mplayer2 input.mp4");
    

    mplayer2 could be controlled using standard input. For instance, when i presss f key in command line, it makes it full screen. how can i send a key to the process?
    I tried these but without any success:

      QProcess *parentProcess = new QProcess();
      parentProcess->setProgram("echo f");
      QProcess *childProcess = new QProcess(parentProcess);
      childProcess->setInputChannelMode( QProcess::ForwardedInputChannel );
      childProcess->start();
      .
      .
      .
      parentProcess->start("echo f");
    

    from documentation:
    QProcess::ManagedInputChannel : QProcess manages the input of the running process. This is the default input channel mode of QProcess.
    QProcess::ForwardedInputChannel : QProcess forwards the input of the main process onto the running process. The child process reads its standard input from the same source as the main process. Note that the main process must not try to read its standard input while the child process is running.

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

      Hi
      Might work with
      process->write("f\n") ;

      https://forum.qt.io/topic/52957/solved-qprocess-run-external-cmd-exe-with-interactive-input/6

      P 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        Might work with
        process->write("f\n") ;

        https://forum.qt.io/topic/52957/solved-qprocess-run-external-cmd-exe-with-interactive-input/6

        P Offline
        P Offline
        Poulad
        wrote on last edited by
        #3

        [SOLVED]

        @mrjj
        Thanks. It solved the problem. Actually i used the following code:

          mplayerProcess->start("mplayer2 --slave --quiet input.mp4");
          ...
          QByteArray command("pause 1\n");
          mplayerProcess->write( command );
        
        1 Reply Last reply
        2

        • Login

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