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 1 Oct 2015, 15:58 last edited by Poulad 10 Jan 2015, 18:15
    #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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 1 Oct 2015, 17:27 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 Oct 2015, 18:14
      1
      • M mrjj
        1 Oct 2015, 17:27

        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 1 Oct 2015, 18:14 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

        1/3

        1 Oct 2015, 15:58

        • Login

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