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. Is it possible to send answer to cmd by QT?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to send answer to cmd by QT?

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 5 Posters 2.8k Views 3 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #21

    @JonB I added code consoleApp.exe ( look at my second post which is started "I have 2 apps:" ). Of course I add this code in this post too:

    #include <QCoreApplication>
    #include "iostream"
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        string answer;
    
        cout<<"Do you prefer forest or sea?";
    
        cin>>answer;
        if(answer == "forest")
        {
            cout<<"You prefer forest!";
        }
        else if(answer == "sea")
        {
            cout<<"You prefer sea!";
        }
        else
        {
            cout<<"This answer is bad!";
        }
        exit(0);
        return a.exec();
    }
    

    I would like to start consoleApp.exe from my mainApp.exe, get the question "Do you prefer forest or sea?" from consoleApp.exe, send the answer "sea" to consoleApp.exe from mainApp.exe, get the output "You prefer sea!" from consoleApp.exe.

    JonBJ 1 Reply Last reply
    0
    • T TomNow99

      @JonB I added code consoleApp.exe ( look at my second post which is started "I have 2 apps:" ). Of course I add this code in this post too:

      #include <QCoreApplication>
      #include "iostream"
      
      using namespace std;
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          string answer;
      
          cout<<"Do you prefer forest or sea?";
      
          cin>>answer;
          if(answer == "forest")
          {
              cout<<"You prefer forest!";
          }
          else if(answer == "sea")
          {
              cout<<"You prefer sea!";
          }
          else
          {
              cout<<"This answer is bad!";
          }
          exit(0);
          return a.exec();
      }
      

      I would like to start consoleApp.exe from my mainApp.exe, get the question "Do you prefer forest or sea?" from consoleApp.exe, send the answer "sea" to consoleApp.exe from mainApp.exe, get the output "You prefer sea!" from consoleApp.exe.

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

      @TomNow99
      Your reply has crossed with my seeing the earlier code, which I think you have just added? You see that we need to see that in order to have a clue what is going on! Please read the EDIT section of my post above, I think that's all your problem is.

      1 Reply Last reply
      3
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #23

        When I add "\n" to write

        proc->write("sea\n");
        

        everything works!

        Thank you all @mrjj @jsulm @SGaist @JonB

        1 Reply Last reply
        1

        • Login

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