3

I have a C# .NET Framework console app on Windows 7. By default, it opens the Windows Command Prompt what seems like the same command line interface that CMD uses to use as its console window. I'd like to change it so it opens and outputs to some other terminal CLI instead. Can this be done?

Edit: It was pointed out that it's not actually using cmd.exe, so I guess I'm looking for how to change the CLI it uses.

TheGreatB3
  • 65
  • 2
  • 7
  • 2
    Why do you want to do this? Have you tried https://stackoverflow.com/a/29700470/34092 ? – mjwills Aug 05 '19 at 14:08
  • 2
    i think you got it backwards. – Daniel A. White Aug 05 '19 at 14:10
  • 1
    @mjwills That could work, but as it says in the answer, it breaks debugging. I guess what I'm asking for is how to make it use a different frontend. A big part of it is formatting. The Windows CMD has a fixed window size and very weird selection. Other terminals have resizable windows, better selection, better color support, better fonts, etc. – TheGreatB3 Aug 05 '19 at 14:30
  • To change the font of your console window, see here: https://stackoverflow.com/a/47014326/1220550 and here: https://learn.microsoft.com/en-us/dotnet/api/system.console. I'd say it should also be possible to change e.g. the width, using similar low level calls. You can also create a shortcut (`program.lnk` that runs `program.exe`) with font and width settings, but those settings don't seem to be honored during VS Debugging sessions. – Peter B Aug 05 '19 at 14:53
  • What happens if you run your app from Powershell? – Dialecticus Aug 05 '19 at 14:56
  • @Dialecticus When I run it from PowerShell, it takes it over and runs normally, just like one would expect. – TheGreatB3 Aug 05 '19 at 15:45
  • One way then would be to run your app from Powershell script (.ps1 file), but that means that you would have to enable running unsigned scripts with `Set-ExecutionPolicy` cmdlet from Powershell. – Dialecticus Aug 05 '19 at 16:11
  • I wish many console / CLI windows (whatever the heck you call it, I don't really care) could be replaced with the terrific Windows Terminal. I guess it's not very possible then – Nicholas Petersen Mar 03 '21 at 21:40

3 Answers3

0

"By default, it opens the Windows Command Prompt" - no, it does not.

A console executable runs in a text-based window; CMD runs in a text-based window; Powershell runs in a text-based window.

Any such type of application does not depend on (or run under) any other such application type, unless you were to start your program using cmd /c program.exe (then it happens because you are instructing cmd to do so), or even using cmd /k program.exe (same, but now telling cmd to keep running and accept commands after program.exe finishes).

Peter B
  • 22,460
  • 5
  • 32
  • 69
0

You can configure your csproj to launch any program you like when you do the command "Start Debugging". I am able to debug my console application using the conshost.exe by opening the project properties, choosing the Debug tab, and under "Start action" selecting "Start external program", then entering "C:\Windows\System32\Conhost.exe". For the command line arguments I enter the name of my output executable. Now F5 will launch my console application using Conhost.exe. You will have to attach the debugger to your process once it starts, since the debugger will start only attached to the Conhost.exe process.

Screenshot of the project debug properties page

John Thoits
  • 355
  • 1
  • 12
0

In Windows 10:

Open Settings > Update & Security > For Developers

Scroll to the bottom and you should see a section called Terminal, in the dropdown select your default terminal application from the installed options.

Terminal Applications

There are many to choose from when Googling, choose the one that suites your style, install it and set it as default.

That said, Microsoft have their new (free) 'Terminal' application, and It's been getting good reviews now that it's past V1.0 Windows Store, GitHub

If you already have it installed, you will be prompted to choose a default terminal application on launch. You can also right click on the top bar to the right of the tab and select settings. Then select your Default Profile, and Default terminal application using the dropdown.

Reahreic
  • 596
  • 2
  • 7
  • 26
  • This doesn't answer what was asked. An application can't control or even know what terminal is used. There are a lot of terminal applications beyond Windows Terminal. IDEs like VS Code, VS, Rider also include terminals – Panagiotis Kanavos Jul 21 '23 at 12:41
  • The answer to the question `"I'd like to change it so it opens and outputs to some other terminal CLI instead. Can this be done?"` is unequivocally `yes`. The instructions for `I guess I'm looking for how to change the CLI it uses.` is what I posted. The OP didn't indicate in their question they wanted a code based solution. In fact the only reason I'm here is I've been fighting UTF-8 encoding BS in the CLI console when I press the green start button in VS and was looking for a way to force my console apps to not use the default legacy CLI while testing. – Reahreic Jul 21 '23 at 12:50
  • You have it backwards. First you start the terminal, then you execute console applications. What you posted doesn't even show how to use different terminal applications, it shows how to install only one of them – Panagiotis Kanavos Jul 21 '23 at 13:10
  • `force my console apps to not use the default legacy CLI while testing.` you have no control over that - the entire Console infrastructure was revamped in Windows 10. You're using the *new* console infrastructure even when you use `cmd` to open the old-style terminal. This is explained in [Introducing the Windows Console (ConPty)](https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/). In short, whatever terminal you want connects to ConnHost, and ConnHost connects to the console app. – Panagiotis Kanavos Jul 21 '23 at 13:16
  • 1
    *I* simply press the green triangle in VS, or double click the .exe. What windows does behind the scenes is a different story. If I were to manually open a CLI/terminal/text-based-interface, then type "C:\MyApp\MyBinary.exe", that would be a different story. At that point I already *chose* my 'text-based-interface' before launching the app. But the Op said `By default, it opens the Windows Command Prompt` indicating they're using the same procedure as I do, and they didn't choose their interface. I read the question's wording as being from a novice user and not someone with 20yrs of CLI use. – Reahreic Jul 21 '23 at 13:44
  • `you have no control over that` Sure, not on a random users computer. But on a windows system under one's own control, you certainly can. On my development & debugging system, the 'Windows Terminal' app now opens instead of 'Windows Console Host' when I press Start in VS, or double click the compiled .exe? I didn't post about using every alternate CLI as the question didn't ask 'how to use them, it asked `how to change the CLI it uses` with my interpretation of the `it` being based on the application 'opening' `the Windows Command Prompt`, and not the CLI 'opening' the application. – Reahreic Jul 21 '23 at 13:56