✅ Closing first terminal, opening second terminal
My main program in
main_app.exe
. When I run my main program, it opens in terminal 1 as expected. When main_app.exe
runs the new process to start a second program, I would like for that second program to open in a new terminal (terminal 2) and the terminal (terminal 1) to be closed. So close current terminal, open new terminal. Then when the second program finishes it's process and relaunches main_app.exe
, I would like for terminal 2 to close, and a new terminal (terminal 3) to open. How would I accomplish this?
TL:DR
1. main_app.exe
=> terminal 1
2. test.exe
=> terminal 2
3. terminal 1 finishes work, opens terminal 2, closes terminal 1
4. terminal 2 finishes work, opens terminal 3, closes terminal 244 Replies
why?
I have tried
I have also looked at https://stackoverflow.com/questions/3616010/start-command-windows-and-run-commands-inside, https://www.google.com/search?client=opera&q=CreateNoWindow+c%23&sourceid=opera&ie=UTF-8&oe=UTF-8, https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.createnowindow?view=net-7.0 and other sites to find a solution. Nothing works
to keep it clean
what if I'm running your app from an already open terminal?
then when the installer starts, it would close the current window, open a new one => installer does its thing, then closes that window and reopens the console back to main application
it's no different than any other application, microsoft included, that are GUI applications that when it runs an update, it closes the current application and opens an updater screen, then when the update is finished, it closes the update window and reopens the applicaiton
just doing it with console instead of a GUI app
huh?
I'm talking about like I already have a terminal open, and run
main_app.exe
, or whatever
you shouldn't be closing my terminal
also, that happens with GUI apps b/c the app that's drawing the window has exited
for a terminal app the app drawing the window is... the terminal
it's not comparableWhats wrong with just doing
your terminal app just should not care
there's no reason for it to do so
I have this currently, but it doesn't close the window
I'm talking about like I already have a terminal open, and run main_app.exe, or whatever you shouldn't be closing my terminal.this is like telling the GUI application that it shouldn't be closing your main applications window because you already have the main applications window open....
What jcotton is likely trying to say is that your program shouldnt need to know who the parent who executed it is. It opens a lot of potential issues up
Console applications arnt windows like a gui app
this is like telling the GUI application that it shouldn't be closing your main applications window because you already have the main applications window open....no it's not the window here is being drawn and maintained by the terminal application not your application it's literally none of your app's business what my terminal window setup is like you're a console app, not a gui app
For example on this, the discord server has a bot called modix which allows for outputting the terminal contents, in a way, its similar
ok so instead of getting passive aggresive responses, would you be inclined to elaborate on what potential issues this could cause by doing what I'm wanting to do with a console based application please?
there's just no reason to do it like that
that's not an explanation of what potential issues it could cause...
Windows Terminal: if you close the main window it either minimizes to tray or closes all terminal instances active in it
ok that I can understand, so what I'm wanting to do would involve opening my second application in a new terminal instance instead of the current terminal instance
so other than the lack of potential issues that it could cause with what I'm wanting to do, I could do an alternative of just clearing the console before the second process starts, and then clearing the console when the second process is finished, yes?
so that I get the window closing effect without actually closing the windows
Console.Clear() doesnt close the terminal instance, it just removes all foreground and background text and formatting. It erases all output from the instance
A "new terminal instance" is dependent on the terminal application
Windows terminal creates new tabs for each "terminal" instance
the old conhost or whatever its called used to have independent instances, but that brings us back to what jcotton said
implementation of that is dependent on the terminal application
ok that makes sense so far
conhost was that version's "Terminal Application", the latest (Windows Terminal) is the current "Terminal Application"
on mac its something different
and on linux too
right. so what would be the best way to go about getting the window close effect without causing any potential harm or problems?
If you use VS Code or Rider they have their own integrated terminals, in those cases, the terminal application would be their own respective processes
VS Code would be its own Terminal application
again, why do you want that effect so bad?
I use visual studio, and I publish my projects to
.exe
's and test from those so that it opens in a legit windows terminalSpecifically check for that specific terminal application and exit your program immediately if its not supported
Potential harm would be: you kill unintended processes
because I like that effect. Is that such a bad thing? At this point I'm aware of your opinion that "it's literally none of your app's business what my terminal window setup is like", and that it can cause potential problems (which is currently being discussed), so I'm asking of a nicer way to go about doing what I want to achieve because it's what i want to do with my application.
so given that the potential harm would be killing unintended processes, I'd rather not do that. I'd rather find a cleaner or nicer way to go about it, even if it is just using
Console.Clear()
to clear the screen in between processes starting/stoppingok. So then I'll just clear the console before/after each new process. no problems there
is this the kind of app someone would start from their terminal?
nope it's an exe file it's a console based application that is packaged down into an exe file that the user would click or double click to open and run that opens in a terminal
You dont necessarily need to create a new terminal instance tbf, you could start your 2nd program and read that info to your first program
eg.
though it would likely be at the point where there's little use to start a new program
since you can already do that in normal code:
well here's a good question for you using that code snippet
what's the difference between
and the code
?
One freezes the entire console application and the other doesnt
oh ok. cool
You cant move your window during that time
so with starting a new process, which one would be more beneficial?
that's a thing for GUI apps, not console ones
Just make it a new method called "DisplayPage2" or something
ah whoops, yea you right
you could do page transitions without needing to start a new process
Thats just this
Also just saying, there's an entire nuget package dedicated to making the console do neat tricks
its called
Spectre.Console
The documentation is found here
Spectre.Console - Welcome!
Spectre.Console is a .NET library that makes it easier to create beautiful console applications.
this is pretty neat
would you mind if I sent you a dm?
I'm actually about to head to bed, i'll read dms when i wake up
ok no problem. thank you for your help