Code::Blocks: How to run within IDE? - c++

When I ask CodeBlocks to run my built application it spawns a terminal window and runs the application within that window. How do I instead get it to run within the IDE's log window?

This is something that is not implemented in Code::Blocks as such.
Target executables are either run directly from the IDE (no console), or via the consolerunner program which calls whatever terminal is appropriate (e.g. cmd under Windows, xterm under Linux) and optionally prompts for a key once the process has exited. Which one it is (terminal or no terminal) depends on the "Type" field in the project's Properties window ("Build Targets" tab).
However, if you absolutely want, you can get the effect of running in the log window indirectly by executing your program as post-build step. In that case, your program's stdout and stderr will both be displayed in the build log tab.

Related

How to prevent tkinter window from closing when I close Windows command console

I open my CMD console to run my main.exe. I type:
python main.exe
My main.exe is a small window written with Tkinter. When I close the command console, my program ends and the window closes. I would like to terminate the console without terminating the program.
edit:
Saving my file as a .pyw doesn't work. Also, the console doesn't just magically appear. I'm not running the script in an IDE. I'm opening it with DOS. The program just closes when I close the cmd console.
Run it with pythonw.exe.
The reason for this is that on Windows executables have a flag to tell the operating system they use a console or not. python.exe expects a console and if if is not already attached to one, it wll create one. pythonw.exe is linked with the GUI flag and does not create a console and if run from a console window will detach from that console.
This is why Tk uses wish.exe on Windows and not tclsh.exe with 'package require Tk' which would be ok on Unix but gives an unwanted console window on Windows.
If changing the extension to .pyw does not help check the program associated with this extension. For instance, on my Windows machine with Python 3.4 I have:
C:\opt\Python>assoc .pyw
.pyw=Python.NoConFile
C:\opt\Python>ftype Python.NoConFile
Python.NoConFile="C:\Windows\pyw.exe" "%1" %*
And pyw.exe does not attach to my console when run.

How to let terminal window be closed automatically in a linux Console Application when run by IDE

When I compile a C++ console application in a Linux IDE like Qt Creator or code::blocks, the terminal window (unlike Windows Console) waits for pressing Enter to be closed. Codes like exit(0) and system("exit") don't work.
Is there any code or option in Qt IDE to let the terminal window (xterm or konsole) be closed automatically after execution.
It is actually made for you. If you build executable of your application and run it from terminal (outside of IDE), it (your application... not the terminal) will close after execution (return in main).
CodeBlocks uses smth called cb_console_runner to run executables and wait for ENTER to close terminal. I am not sure how is it possible to make it work without cb_console_runner
EDIT: In codeBlocks... remove/rename cb_console_runner in /bin and it is solved:)
to make it easier: run this command:
sudo mv /bin/cb_console_runner cb_console_runner_s
In QtCreator in Project->Run settings
uncheck "Run in Terminal"

C++ disallow command prompt from displaying

Is there any thing I can do to make sure that the shell/command prompt does not show up when I run my C++ program, it is meant to be a background program? While it isn't a huge deal if it displays because it quickly closes, I would prefer it doesn't display at all. Program will run on windows xp/vista/7 OS
Configure your compiler or linker to mark your program as a GUI application.
Windows recognizes two main types of programs: GUI and console. If the EXE header is marked as a console program, then the OS creates a console window prior to executing it. Otherwise, it doesn't. This isn't something you can control at run time; you need to set it at link time. (You can call ShowWindow(GetConsoelWindow(), SW_HIDE) to try to control it at run time, but that doesn't prevent the window from flickering on and then off again. Plus, if your program is sharing the console with another program, like cmd.exe, then you'll have just hidden the user's command-prompt window!) Even if your program doesn't have any actual GUI, that's still the mode you need to avoid having a console window created for you.
If you're starting a new project in Visual Studio, select the "Win32 Console Application" option. If you already have a project, then in your project's configuration properties, find the "Subsystem" setting of the "Linker/System" section and set it to "Console." That makes the linker use the /subsystem:console option. If you're using Mingw, use the -Wl,--subsystem,windows option.
Sounds to me like you want to create a Windows service, not a command line utility. This is why services exist. Long running background tasks that require no user interaction. A simple example here.

How to hide console window in Mac OS (gcc compiler)?

I write an application with Code::Blocks IDE in Mac OS (C++ application).
CodeBlocks uses gcc to compile the source code.
When I double click on the output of the project (executable binary file), my application executes correctly but a console application shown. My application is a background application without any reading or writing to console, and I add it to startup items. I don't want when I logon, a balnk console (of my application) shown. I want to hide the console window.
How to hide console window in Mac OS with gcc compiler?
It sounds like what you are developing is a daemon (background process that is launched when a user account is logged on, or system is launched). OS X uses launchd and launchctl to manage daemons, so you'll need to set up the proper plist entry in either the /System/Library/LaunchAgents (to launch during system boot) or ~/Library/LaunchAgents (to launch when a user logs in) directory, and register it with launchctl.

Eclipse C++ - output to window DOS

I am using Eclipse with C++. When I run the program, I get the following message in my Console window:
**** Build of configuration Debug for project Disks Repulsion ****
**** Internal Builder is used for build ****
Nothing to build for Disks Repulsion
I makes changes to the program and run it again, and this time I get following message:
**** Build of configuration Debug for project Disks Repulsion ****
**** Internal Builder is used for build ****
g++ -oDisksRepulsion.exe DisksRepulsion.o -lopengl32 -lglu32 -lglut32
C:\MinGW\bin..\lib\gcc\mingw32\3.4.5........\mingw32\bin\ld.exe: cannot open output file DisksRepulsion.exe: Permission denied
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 103 ms.
When I first ran the program, it started my program (I can see it running in my Window Task Manager), but there is no output being sent to the console.
After making changes to my program, the program is still running in the background, so I get the "Permission denied" error, when I try to run the program. I can make the error go away by ending the instances via task manager. However, when I run the program, I still don't see any output being sent to the console.
Yesterday, I was able to see the output in my console, but don't know why I cannot see it today. Also, when I saw my output, the cursor's focus did not change from the code to the console. I dislike having to do it manually.
I also don't like that when I make changes to my program, and run it again, that the program is not automatically terminated on its own.
I have used VC++ and I prefer the window Dos for output. So, I wanted to know if there is anyway in Eclipse to send the output to Windows Command Prompt, since I know that the instance of the .exe is really gone when I close the program. It automatically gets cursor's focus. I will also be able to get some output.
I installed MinGW with MaSYS or something, to compile the program.
It sounds like your application isn't terminating on its own and you didn't build in any sort of interface that would allow you to kill the program. This sounds like a bug in your code and not an Eclipse issue. If issuing a Ctrl+C in the console won't kill your program, then look into coding something that will let you kill your app with keystroke or input sequence.
If you want to run your app in a command console, then open a normal command console, browse to the folder containing your project, and run the compiled executable from the console instead of doing it through the Eclipse interface.
A simple solution, which I've been using for ages now, is opening a command prompt yourself and running the executable manually. An advantage of this method is that you can set your "DOS" window's size to anything you want. (Right now I'm using a 120x50 window with 8192 lines of scrollback buffer.) Another one is that you will never lose your console output; in fact, you'll be able to see outputs from past runs. (8192 lines is A LOT unless you're printf-debugging a tight loop.)
An alternative to terminating your program from the taskbar is using the red icons on the top right corner of the Eclipse "Console" window.
Is your program's entrypoint main() or WinMain()? There may also be a setting/link option for the "subsystem," console or Windows I think they're called in Visual Studio.
Anyway, if your program is starting up via WinMain, the expectation is that you'll have a Windows form of some sort through which the user can control the program. If you use main(), then your program should automatically trigger the opening of a console window.
Look up AllocConsole() on MSDN (or google it) if you are using WinMain() intentionally and want a console window to also open up. There's some trickery also available via google search that can hook stdout to this console, but at this time I don't remember what it is. (You basically redirect the stdout handle to your new console.)
Good luck.