I have an application and I want it to somehow open a new command line window for input. Is there a way to do this with C ?
CodePudding user response:
To open a terminal or any other process, you need to call it.
For example, I use ubuntu OS and for open terminal If I say gnome-terminal
, it will open it as I run my program.
This is that code:
#include <cstdlib>
int main()
{
std::system("gnome-terminal");
return 0;
}
For windows, you should call your cmd process. means that instead of gnome-terminal
you need to write cmd
or your process name
CodePudding user response:
I'm not sure what is your "application" in this case. However, for applications to interact with each other, usually we would need some kind of APIs (Application Programming Interface), so that what you have on another application (a new terminal as you said) could be properly used in the "main" application.
If your desired result is just to get another terminal opened, we just have to call it. But remember, every Operating System has its own way to open a terminal, so if you like to automate everything, we have to use macros
to check to current OS of the user, here is a suggestion:
#include <cstdlib>
int main()
{
#ifdef _WIN32
std::system("start program.exe");
// program.exe is app you have built to get input.
#endif
#ifdef _WIN64
std::system("start program.exe");
#endif
#ifdef __APPLE__
std::system("open program");
#endif
#ifdef __linux__
std::system("open program");
#endif
// #ifdef and #endif are just like if - statement.
}
Every compiler has the macros
like _WIN32
-stands for windows 32bit, _WIN64
-windows 64bit, and so on. Its pretty handy to use them.
Hope this helps!