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. Cannot write to a process

Cannot write to a process

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 3 Posters 2.0k 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.
  • Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #6

    @smallC said in Cannot write to a process:

    How to do it? (Using QProcess of course)

    See QProcess::start()

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    S 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @smallC said in Cannot write to a process:

      How to do it? (Using QProcess of course)

      See QProcess::start()

      S Offline
      S Offline
      smallC
      wrote on last edited by smallC
      #7

      @Christian-Ehrlicher
      Am afraid you got it wrong.
      I'm not trying to send arguments to the git process during start up of this process.
      I'm trying to write through write channel to that git process AFTER the process had already started.
      This is something different to passing arguments to a process when we start that process from command line.
      What I'm trying to do is to communicate with that process via stdin stdout channels.

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #8

        @smallC said in Cannot write to a process:

        I'm trying to write through write channel to that git process AFTER the process had already started.

        Again: git has no interactive mode so you can't send anything to it when the process runs.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        S 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @smallC said in Cannot write to a process:

          I'm trying to write through write channel to that git process AFTER the process had already started.

          Again: git has no interactive mode so you can't send anything to it when the process runs.

          S Offline
          S Offline
          smallC
          wrote on last edited by smallC
          #9

          @Christian-Ehrlicher
          I can. I do it on Windows with the exact code I've posted.
          On Windows this code works as intended:
          I'm starting git process via QProcess with start() method.
          Then, when the process started I communicate with that process via write and readAllStandardOutput methods of QProcess.
          So when I do:
          process.write("git status");
          I'm getting git status output as if I were to type it in the console, so when I execute this:
          auto output = process. readAllStandardOutput();
          in this^^^ output field I'm getting output from git.

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #10

            Even on windows it works only by accident. When you click on git.exe on windows there will be no command prompt which stays open - so no interaction possible.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            S 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Even on windows it works only by accident. When you click on git.exe on windows there will be no command prompt which stays open - so no interaction possible.

              S Offline
              S Offline
              smallC
              wrote on last edited by smallC
              #11

              @Christian-Ehrlicher You're joking. You must be. Did you ever hear about communication between processes? For example writing to other process stdin and reading from such process stdout?

              Christian EhrlicherC 1 Reply Last reply
              0
              • S smallC

                @Christian-Ehrlicher You're joking. You must be. Did you ever hear about communication between processes? For example writing to other process stdin and reading from such process stdout?

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #12

                @smallC said in Cannot write to a process:

                For example writing to other process stdin and reading from such process stdout?

                I did, but git does not do it (don't know how often I have to repeat it) - git is not interactive. Simply call 'git status' and you're done.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                S 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @smallC said in Cannot write to a process:

                  For example writing to other process stdin and reading from such process stdout?

                  I did, but git does not do it (don't know how often I have to repeat it) - git is not interactive. Simply call 'git status' and you're done.

                  S Offline
                  S Offline
                  smallC
                  wrote on last edited by
                  #13

                  @Christian-Ehrlicher
                  Please post the code you want me to execute in order to get reply from git to the "git status" command.
                  I've tried the start command with program and params list and it doesn't work.

                  JonBJ 1 Reply Last reply
                  0
                  • S smallC

                    @Christian-Ehrlicher
                    Please post the code you want me to execute in order to get reply from git to the "git status" command.
                    I've tried the start command with program and params list and it doesn't work.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #14

                    @smallC
                    You are running a command of "/usr/bin/git", and then sending the string "git status\n" to its standard input. That makes no sense at all, what would git begin to do with a command starting with git... even if it worked this way?

                    I don't know what you claim it's doing under Windows. I don't want to get into a debate about that. Here you must be under Linux ("/usr/bin/git"), so if you don't agree and think what you had should work I invite you to man git and find where you says it will read commands from stdin as you say rather than accept status as an argument which is what I/ @Christian-Ehrlicher say.

                    Since you need to run git status you need to pass status as an argument on the command-line to git. You need:

                    process.start(git_process_path, QStringList() << "status");
                    // or, if you prefer
                    process.setProgram(git_process_path);
                    process.setArguments(QStringList() << "status");
                    process.start();
                    

                    You can then read from its standard output. However, you really should also read from its standard error too, at present you are leaving anything it might write to stderr to vanish into the blue. Separately from that, for production code at least, you should be checking for error return code.

                    S 1 Reply Last reply
                    1
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      @smallC said in Cannot write to a process:

                      Please post the code you want me to execute in order to get reply from git to the "git status" command.
                      I've tried the start command with program and params list and it doesn't work.

                      Please post your code - I won't write code for you. But basically it's just QProcess::start(), QProcess::waitForFinished() (not recommended, use signals/slots) and the QProcess::readAllStandardError()/QProcess::readAllStandardOutput()

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      S 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @smallC said in Cannot write to a process:

                        Please post the code you want me to execute in order to get reply from git to the "git status" command.
                        I've tried the start command with program and params list and it doesn't work.

                        Please post your code - I won't write code for you. But basically it's just QProcess::start(), QProcess::waitForFinished() (not recommended, use signals/slots) and the QProcess::readAllStandardError()/QProcess::readAllStandardOutput()

                        S Offline
                        S Offline
                        smallC
                        wrote on last edited by smallC
                        #16

                        @Christian-Ehrlicher
                        I did post my code. In OP.

                        1 Reply Last reply
                        0
                        • JonBJ JonB

                          @smallC
                          You are running a command of "/usr/bin/git", and then sending the string "git status\n" to its standard input. That makes no sense at all, what would git begin to do with a command starting with git... even if it worked this way?

                          I don't know what you claim it's doing under Windows. I don't want to get into a debate about that. Here you must be under Linux ("/usr/bin/git"), so if you don't agree and think what you had should work I invite you to man git and find where you says it will read commands from stdin as you say rather than accept status as an argument which is what I/ @Christian-Ehrlicher say.

                          Since you need to run git status you need to pass status as an argument on the command-line to git. You need:

                          process.start(git_process_path, QStringList() << "status");
                          // or, if you prefer
                          process.setProgram(git_process_path);
                          process.setArguments(QStringList() << "status");
                          process.start();
                          

                          You can then read from its standard output. However, you really should also read from its standard error too, at present you are leaving anything it might write to stderr to vanish into the blue. Separately from that, for production code at least, you should be checking for error return code.

                          S Offline
                          S Offline
                          smallC
                          wrote on last edited by
                          #17

                          @JonB
                          Hi thanks,
                          That indeed worked. My mistake was that I was thinking of /usr/bin/git in terms of git executable on Windows.
                          Thanks for your help.

                          JonBJ 1 Reply Last reply
                          1
                          • S smallC

                            @JonB
                            Hi thanks,
                            That indeed worked. My mistake was that I was thinking of /usr/bin/git in terms of git executable on Windows.
                            Thanks for your help.

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #18

                            @smallC
                            I think your original way worked under Windows because of the git implementation there, only. I look at https://gitforwindows.org/ and I see it talking about

                            Git BASH

                            Git for Windows provides a BASH emulation used to run Git from the command line. *NIX users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.

                            and the screenshot at https://gitforwindows.org/img/gw1.png. I think they are saying in their Windows git that a command of git alone enters a "shell", kind of emulating Linux bash, which allows you to type things like git status into it, and it stays there and executes. Perhaps not quite, but something like that anyway. That is not a facility of git under Linux. probably why your stuff worked under Windows and not Linux?

                            S 1 Reply Last reply
                            1
                            • JonBJ JonB

                              @smallC
                              I think your original way worked under Windows because of the git implementation there, only. I look at https://gitforwindows.org/ and I see it talking about

                              Git BASH

                              Git for Windows provides a BASH emulation used to run Git from the command line. *NIX users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.

                              and the screenshot at https://gitforwindows.org/img/gw1.png. I think they are saying in their Windows git that a command of git alone enters a "shell", kind of emulating Linux bash, which allows you to type things like git status into it, and it stays there and executes. Perhaps not quite, but something like that anyway. That is not a facility of git under Linux. probably why your stuff worked under Windows and not Linux?

                              S Offline
                              S Offline
                              smallC
                              wrote on last edited by
                              #19

                              @JonB
                              Yes, in Windows it opens a bash/cmd and you can write/read from it. It works differently on Linux. I wasn't aware of that. I thought that the /usr/bin/git<<this git, is an equivalent to Windows git.exe. That's why the confusion.
                              Thanks for your help.

                              JonBJ 1 Reply Last reply
                              1
                              • S smallC

                                @JonB
                                Yes, in Windows it opens a bash/cmd and you can write/read from it. It works differently on Linux. I wasn't aware of that. I thought that the /usr/bin/git<<this git, is an equivalent to Windows git.exe. That's why the confusion.
                                Thanks for your help.

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #20

                                @smallC
                                Indeed. FWIW, if you do want to support Windows too I think the Linux command-line-arguments-only will work there too, but not the other way round, though you'd have to verify.

                                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