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. Writing to the standard input of a process
Forum Updated to NodeBB v4.3 + New Features

Writing to the standard input of a process

Scheduled Pinned Locked Moved General and Desktop
23 Posts 3 Posters 15.8k Views 2 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.
  • A Offline
    A Offline
    A1exander_Z
    wrote on last edited by
    #14

    I am not sure how to call a standard cmd command from a Qt application (I have tried process->setProgram("dir"), it runs but produces no output to stdout), but I did further research.

    I wrote a simple program in C++ and compiled it with MinGW:

    @#include <iostream>
    #include <string>

    int main(int argc, char *argv[])
    {
    std::string s;
    std::cin >> s;
    std::cout << s << std::endl;
    }@

    It works both with and without process->waitForFinished() call, my Qt application can write to its standard input and retreive echoed string from its output. Writing from a slot connected to the 'QProsess::started' signal also works. It seems that the problem is with my C# program after all.

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

      Did you try with a similar minimal application written in C# ?

      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
      • A Offline
        A Offline
        A1exander_Z
        wrote on last edited by
        #16

        Yes, I have tried this:

        @class Program
        {
        static int Main(string[] args)
        {
        string s;
        s = Console.ReadLine();
        Console.WriteLine(s);
        return 0;
        }
        }@

        Works if I place waitForFinished() call after writing to the standard input of the process, but never terminates without it. Changing configuration of the C# program from Debug to Release in Visual Studio does not help.

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

          Maybe a silly question (I don't know much about C#) but aren't you missing a "\n" here ?

          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
          • A Offline
            A Offline
            A1exander_Z
            wrote on last edited by
            #18

            No, Console.WriteLine() method inserts it automatically. And with waitForFinished() call it works even when I change Console.WriteLine() to Console.Write(), which does not insert a newline symbol.

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

              Could there be some subtle difference on how the C# runtime uses stdin/stdout ?

              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
              • A Offline
                A Offline
                A1exander_Z
                wrote on last edited by
                #20

                Yes, it seems that there is some difference, but I am not a C# expert and I have no idea what it is. I will try a simple program compiled using Mono but for now, I think it is easier to send all data as command line parameters.

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

                  As long as it's clean and works, do what is best.

                  Happy Coding !

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

                  M 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    As long as it's clean and works, do what is best.

                    Happy Coding !

                    M Offline
                    M Offline
                    mhmdkanj
                    wrote on last edited by
                    #22

                    @SGaist I am currently having the same issue for C# executables and writing to their standard input. Assuming that I cannot change the C# code, how would I fix this in Qt in case you can enlighten me after a few years.. Many thanks!

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

                      hi,

                      Did you apply the same technique as @A1exander_Z did ?

                      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

                      • Login

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