When compiling this program in GCC-mingw32 and trying to run it, it always pops up a Console Window in a very short time and closes immediately.
int main (void)
{
system("shutdown -s -t 60"); // Shutdown the computer in 1 minute
return 0;
}
How could I modify this code in order to run it without any window pops up?
Is it feasible?
Thanks.
Your executable is being marked as using the console subsystem, which makes Windows show a console window automatically. If you change it to use the GUI subsystem, Windows won't show a console window. To tell MinGW to use the GUI subsystem, pass the -mwindows flag.
Related
I need my C program to run in the background, so without any open window or without blocking the terminal if run from there.
I can't find much info on how to do it online.
edit: To do what i needed, i just added -mwindows to the gcc command.
Windows supports two program types; GUI and console.
Console applications automatically get a console window if the parent process does not already have one.
GUI applications do not get a console and they can have 0, 1 or multiple windows. If you don't create a window your application is basically only visible in Task manager. GUI applications typically use WinMain as the startup function instead of main. Notepad.exe is a GUI application that creates a window.
You need to tell the compiler/linker that you are creating a GUI program. If you are using Visual Studio, it probably has a project template you can use.
I have made a c program with codeBlocks on windows 10, but the exe crashes as soon as I open it, actually it does not matter the program all exe produced by codeblocks won't run, maybe there are some problems with the settings? Cause if I run the program from inside codeBlocks it runs without problems, any suggestion?
You are compiling "command line programs", which don't open a window on their own. Since they apparently don't expect any user input they run to the end quite happily and quit.
If you want to run this type of programs, you need a shell, which provides a window.
This is a simple way to get one: Open a file explorer window and navigate to the directory containing your program. Click into the address bar so that it changes into a textual representation of the path. Replace all of it with the word cmd and press enter. Now the shell's window opens, commonly with white text on a black background. Enter the name of the program, and it will run.
I'm trying to debug a simple program of several line with gdb from the command line.
The problem is that whenever I run the program it runs the program and then automatically assume that I wanted to quit and quit gdb for me.
I'm using gcc compiler and I've updated the version (which solved another problem that I had).
to clarify the problem is that it is not me who entered the quit command after the run command, gdb generates it automatically without asking me and then assumes yes.
I fixed this problem by running gdb in a cygwin window rather than a Windows command window. I get the cygwin window by running (i.e., double-clicking on) mintty.exe, which on my machine is at
C:\cygwin64\bin\mintty.exe
There's this bug with the placement of certain characters in the embedded terminal in CLion (the Run tab that pops up when you click the Run button), and I figured out that if I changed the terminal in CLion, that wouldn't happen. I changed the terminal to cmder, and it is all working now, except one thing: I can't figure out how to make CLion run the program to that terminal.
I tried changing the configuration, but all it did on run was open cmder but not execute the program (I had to run it manually, by writing the file name).
I wonder, what's the way to fix this, and make CLion directly run C programs on the terminal, instead of the Run tab?
Thank you.
The CLion run configuration always runs in the integreted run window. That is not a terminal emulator, and it cannot be changed so that it runs in an actual terminal emulator (like cmder).
Your best bet is to try to fix the "character placement" in the run window. Maybe ask a different question where you explain the issue, or if it's a clear bug, file a bug report for it.
I'm trying to debug my ncurses application, using gdb. I use tty command to redirect program's I/O to another terminal. Output works like a charm, but I'm having problems with input. I'm using getch() function to retrieve symbols in my app. So, for instance, if I do in my gdb session:
tty /dev/pts/5
I get my output in another tab of my terminal window (gnome-terminal). My gdb sessions is getting stuck, waiting for input, but when I press any key within my /dev/pts/5 I get it printed out, but the app itself does not except it as an input symbol. When running without gdb everything works fine, I'm also using noecho(), so symbols should not be displayed.
So, what's the problem? Is it possible to somehow handle input from redirected terminal?
You can attach to your process to debug from a different terminal instead of trying to run the application from within gdb.
Run your process as normal. When it is blocked for user input, find its process ID, and then attach to it with gdb from a different window:
gdb -p <PID>
Your problem is due to the program still expecting its interactive input to be coming from your gdb session.
Maybe it's a bit late to answer, but hope this helps:
It took some time to figure out how to debug ncurses applications,
finally i made a very comfy way with the help of gdbserver and tmux.
This way I/O of gdb and the application are completely separated:
debug.sh (the script that starts debugging):
#!/bin/bash
tmux splitw -h -p 50 "gdbserver :12345 ./yourapplication"
tmux selectp -t 0
gdb -x debug.gdb
debug.gdb (one-liner gdb scriptfile for comfort):
target remote localhost:12345
So this way, application starts up on right side, gdb on left waiting to hit continue or any other usual gdb stuff :)
Once you exit, tmux automatically closes the gdbserver (therefore right panel as well) and that's all :)