Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Get exit code in terminal

Get exit code in terminal

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
11 Posts 6 Posters 263 Views 1 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.
  • P Offline
    P Offline
    Programist
    wrote last edited by Programist
    #1

    Hello, I'm using the latest version of Qt Creator to write C code in Windows 10.
    How can I make the exit code appear in the external terminal? The exit code shows up when I have checked "Use internal terminal" however I prefer to have the terminal open up in a separate window. Unfortunately it doesn't show the exit code, only "Press <RETURN> to close this window...".

    Code::Blocks has such a terminal (cb_console_runner.exe), so maybe there is a way I can integrate it in Qt Creator? I've previously done exactly that in KDevelop by tweaking the "Launch Settings", but I'm struggling to do that in Qt Creator.

    Anyway, either making Qt Creator's terminal show the exit code or using the one from Code::Blocks will be fine. Thanks in advance!

    cristian-adamC 1 Reply Last reply
    0
    • aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi @Programist,

      that seems indeed a difference between internal and external Terminal.

      If its any help: You can open the Application Output and it will show the result of the last run also ("finished successfully" resp. "finished with code X".

      Maybe that already helps you.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SimonSchroeder
        wrote last edited by
        #3

        The terminal window will run a regular shell (e.g. bash on Linux). Normal shell behavior is to not show the exit code. What you could do in QtCreator is to write a small script that launches your program and then prints its exit code. You can specify in QtCreator to run your script instead.

        JonBJ 1 Reply Last reply
        0
        • S SimonSchroeder

          The terminal window will run a regular shell (e.g. bash on Linux). Normal shell behavior is to not show the exit code. What you could do in QtCreator is to write a small script that launches your program and then prints its exit code. You can specify in QtCreator to run your script instead.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by JonB
          #4

          @SimonSchroeder said in Get exit code in terminal:

          You can specify in QtCreator to run your script instead.

          I read up yesterday to suggest this and (I think) it says you cannot do that under Windows? You can choose what is run for the external terminal under Linux (e.g. xterm) but not Windows? So I didn't suggest it.

          S 1 Reply Last reply
          0
          • JonBJ JonB

            @SimonSchroeder said in Get exit code in terminal:

            You can specify in QtCreator to run your script instead.

            I read up yesterday to suggest this and (I think) it says you cannot do that under Windows? You can choose what is run for the external terminal under Linux (e.g. xterm) but not Windows? So I didn't suggest it.

            S Offline
            S Offline
            SimonSchroeder
            wrote last edited by SimonSchroeder
            #5

            @JonB Are you sure? I would expect that you can run a .bat file instead...

            I am on Windows and there is an option to select the "executable". I don't see a reason why this cannot be a .bat file (or a call to cmd that immediately executes the .bat file). And it is possible to get the return code in the good old Windows command line. (Though, I haven't tested it.)

            JonBJ 1 Reply Last reply
            0
            • J.HilkJ Online
              J.HilkJ Online
              J.Hilk
              Moderators
              wrote last edited by
              #6

              QtC is already running a bat file to set up the compiler environment. So should be possible


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0
              • S SimonSchroeder

                @JonB Are you sure? I would expect that you can run a .bat file instead...

                I am on Windows and there is an option to select the "executable". I don't see a reason why this cannot be a .bat file (or a call to cmd that immediately executes the .bat file). And it is possible to get the return code in the good old Windows command line. (Though, I haven't tested it.)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote last edited by
                #7

                @SimonSchroeder said in Get exit code in terminal:

                @JonB Are you sure?

                Absolutely not, I don't use Windows! My comment based on https://doc.qt.io/qtcreator/creator-reference-terminal-view.html

                To open the terminal in a separate window, go to Preferences > Terminal, and clear Use internal terminal.

                On Linux and macOS, you can set the terminal to open by selecting Preferences > Environment > System.

                Hence I assume not on Windows?

                S 1 Reply Last reply
                0
                • JonBJ JonB

                  @SimonSchroeder said in Get exit code in terminal:

                  @JonB Are you sure?

                  Absolutely not, I don't use Windows! My comment based on https://doc.qt.io/qtcreator/creator-reference-terminal-view.html

                  To open the terminal in a separate window, go to Preferences > Terminal, and clear Use internal terminal.

                  On Linux and macOS, you can set the terminal to open by selecting Preferences > Environment > System.

                  Hence I assume not on Windows?

                  S Offline
                  S Offline
                  SimonSchroeder
                  wrote last edited by
                  #8

                  @JonB I was thinking about the projects run configuration where there is a check box "Run in terminal". (This one is also there on Windows.)

                  1 Reply Last reply
                  0
                  • P Programist

                    Hello, I'm using the latest version of Qt Creator to write C code in Windows 10.
                    How can I make the exit code appear in the external terminal? The exit code shows up when I have checked "Use internal terminal" however I prefer to have the terminal open up in a separate window. Unfortunately it doesn't show the exit code, only "Press <RETURN> to close this window...".

                    Code::Blocks has such a terminal (cb_console_runner.exe), so maybe there is a way I can integrate it in Qt Creator? I've previously done exactly that in KDevelop by tweaking the "Launch Settings", but I'm struggling to do that in Qt Creator.

                    Anyway, either making Qt Creator's terminal show the exit code or using the one from Code::Blocks will be fine. Thanks in advance!

                    cristian-adamC Offline
                    cristian-adamC Offline
                    cristian-adam
                    wrote last edited by cristian-adam
                    #9

                    @Programist Do open a bug report / feature request. Qt Creator uses a process_stub process that could print the process output, just like the internal terminal does.

                    Edit: If you want to hack Qt Creator, you could do this:

                    --- src/tools/process_stub/main.cpp
                    +++ src/tools/process_stub/main.cpp
                    @@ -189,7 +189,9 @@ void doExit(int exitCode)
                             controlSocket.waitForBytesWritten(1000);
                     
                         if (!commandLineParser.value("wait").isEmpty()) {
                    -        std::cout << commandLineParser.value("wait").toStdString() << std::endl;
                    +        std::cout << "Process existed with code " << exitCode << "." << std::endl
                    +                  << std::endl
                    +                  << commandLineParser.value("wait").toStdString() << std::endl;
                     
                             waitingForExitKeyPress = true;
                             onKeyPress([] { doExit(0); });
                    

                    Then you would get the expected result:

                    qtcreator-return-code-external-terminal.png

                    JonBJ 1 Reply Last reply
                    2
                    • cristian-adamC cristian-adam

                      @Programist Do open a bug report / feature request. Qt Creator uses a process_stub process that could print the process output, just like the internal terminal does.

                      Edit: If you want to hack Qt Creator, you could do this:

                      --- src/tools/process_stub/main.cpp
                      +++ src/tools/process_stub/main.cpp
                      @@ -189,7 +189,9 @@ void doExit(int exitCode)
                               controlSocket.waitForBytesWritten(1000);
                       
                           if (!commandLineParser.value("wait").isEmpty()) {
                      -        std::cout << commandLineParser.value("wait").toStdString() << std::endl;
                      +        std::cout << "Process existed with code " << exitCode << "." << std::endl
                      +                  << std::endl
                      +                  << commandLineParser.value("wait").toStdString() << std::endl;
                       
                               waitingForExitKeyPress = true;
                               onKeyPress([] { doExit(0); });
                      

                      Then you would get the expected result:

                      qtcreator-return-code-external-terminal.png

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote last edited by JonB
                      #10

                      @cristian-adam
                      If you/someone is going to use that code to really patch Creator, adjust its spelling to report "exiting" rather than "existence" ;-)

                      cristian-adamC 1 Reply Last reply
                      2
                      • JonBJ JonB

                        @cristian-adam
                        If you/someone is going to use that code to really patch Creator, adjust its spelling to report "exiting" rather than "existence" ;-)

                        cristian-adamC Offline
                        cristian-adamC Offline
                        cristian-adam
                        wrote last edited by
                        #11

                        @JonB said in Get exit code in terminal:

                        @cristian-adam
                        If you/someone is going to use that code to really patch Creator, adjust its spelling to report "exiting" rather than "existence" ;-)

                        🤣

                        Sometimes the fingers have their own mind.

                        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