20 ms·
Rumors of Cmd’s death have been greatly exaggerated
- quotemstr 10y agoWindows really needs a public psuedoconsole API. For the uninitiated: cmd.exe is the shell, like bash. conhost.exe is the terminal emulator, like xterm. bash or cmd (the shell) talks to the terminal via its standard input, output, and error file handles. Terminal handles are like full-duplex pipes, but richer: they transmit all the information needed for interaction with the user. Each terminal handle has two ends: master* and slave. The slave is the terminal to which cmd or bash talks; it basically emulates a teletype. The master handle allows for reading both in-band and out-of-band information from the slave terminal handle and supports special APIs that allow anyone with access to the master handle to fully emulate a terminal. POSIX systems allow anyone to create master and slave terminal handles. When you start xterm, xterm calls openpty, gets master and slave handles, starts your shell with the slave handle, and uses the master terminal to get the information needed to draw characters. There's no equivalent for Windows. The only Windows program that can call the Windows equivalent of openpty is conhost, which ships with the operating system. It's not possible for a different program to make a master-side terminal handle. There are two workarounds, which both suck: 1) use pipes, not console handles, and 2) make a hidden conhost.exe and scrape it. The former causes programs to think they're being run non-interactively, with all sorts of negative side effects (like excessive buffering). The latter loses screen updates, is inefficient, and is generally awful. Microsoft could easily make this situation much better by opening the protocol that conhost uses to communicate with the kernel. If any program can create a console handle, it's much easier to implement things like ssh daemons, Cygwin, and terminal emulators that suck less than conhost. ... * As an aside: when bash talks to xterm, it uses in-band signaling (mostly: see termios): it sends control code sequences, which xterm understands as "move cursor to 3,3" and "set color to green". By contrast, when cmd communicates to conhost, it uses out-of-band signaling: it uses special API functions to move the cursor and set the text color.
- bpye 10y agoIs there any historical reason that conhost is the only executable able to open a master handle?
- quotemstr 10y agoWell, originally, console handles weren't real handles. They were userspace hacks, which is why DuplicateHandle[1] has special cases for console handles. (Imagine using negative file descriptor values that libc understood.) Originally, the terminal emulator ran as SYSTEM and was spawned from (IIRC) csrss (which is special, because reasons). In Vista, with integrity levels introduced, the terminal emulator had to run in a different security context, and so wasn't themed. (To prevent shatter attacks.) In Windows 7 and 8, Microsoft developed a real, honest-to-god pseudoconsole API, with a real protocol. In this implementation, console handles are real handles and conhost is just a normal program that speaks a protocol. IIRC, the only thing at this point stopping Microsoft creating a pseudoconsole API based on real, honest-to-god kernel HANDLEs is a willingness to externalize, document, and support what has been until now a Windows-internal API. [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms724251(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms7...
- dman 10y agoHow do you know all this? :)
- quotemstr 10y agoThree years on Windows and Windows Phone. I sometimes miss those days. :-)
- dfox 10y agoOn Vista, conhost.also ran in user context and console windows were themed, on XP they was not. I believe that conhost.exe was introduced in Vista together with new desktop separation mechanism and on earlier version all the console window logic was internal to csrss (which in original NT design was essentially display server and window manager and placing console emulation in there makes some kind of sense given the NT's model of that).
- mtdewcmu 10y agoIf Cmd is not going away, why doesn't MS invest in it and make it more useful? It could learn a few things from xterm, bash, etc.
- serge2k 10y agoThey have powershell for that.
- mtdewcmu 10y agoThey said themselves that PowerShell is not a replacement for Cmd...
- Ericson2314 10y agoNot a literal replacement, but no they want you to use PowerShell instead of CMD (and for good reason).
- mtdewcmu 10y agoI get that they want to push PowerShell.
- throwaway7645 10y agoI've been using Powershell a lot lately. I keep hoping I'll get the hang of it, but everything sucks. It gives you Compare-Object, but what it returns is an object. Even if I waste 10 minutes converting it to text and want to then split the strings it returns there is a 99% chance it won't work. Sure it is great for automating a few IT things like installing new users, but the problem is it shouldn't be that hard. In bash I would just pipe the output of diff to Awk and simply split on "," and tell it to print what I want. I'm sure it is possible in Powershell, but the 6 ways I tried never worked.
- sixothree 10y agoSame here. Every time I've completed a script I can't help but think I could have finished it so much faster in C# or just about any other language. I tried liking it. Maybe I'm just not finding the right useful examples.
- gcb0 10y agounfortunately.
- snambi 10y agoInstead they can adopt linux and release a Microsoft Linux. Why bother about windows?
- andrewclunn 10y ago> Cmd is one of the most frequently run executables on Windows with a similar number of daily launches as File Explorer, Edge and Internet Explorer! Wait, they track that?
- brightball 10y agoAlso my first reaction
- herbst 10y agoI was more surprised seeing internet explorer in that list
- symlinkk 10y agoI would be interested to know why you are being downvoted.
- ralish 10y agoBecause it's well known by anyone interested in this area? There's been a barrage of "Windows 10 Telemetry/Privacy" related stories since its release. It's also publicly documented by Microsoft itself: https://technet.microsoft.com/en-au/itpro/windows/manage/configure-windows-telemetry-in-your-organization?f=255&MSPPError=-2147217396 https://technet.microsoft.com/en-au/itpro/windows/manage/con... "Performance and reliability data, such as which programs are launched on a device, how long they run, how quickly they respond to input, how many problems are experienced with an app or device, and how quickly information is sent or received over a network connection."
- andrewclunn 10y agoBecause it's a comment that asks a question based on actually reading the linked article, and this is hacker news.
- ygra 10y agoThere has been an opt-in for »Share anonymous usage details with Microsoft to make stuff better« since ages in Windows and other Microsoft products. So if yo enabled that, I presume they will log telemetry about what features of Windows are used, how often, together with which other features, etc. I wouldn't expect that to extend to non-Windows programs since there's little they can learn from it.
- sean_patel 10y agoFrom the Article: > Notice the nuance here: The above paragraph states that “[PowerShell] replaces Command Prompt (aka, “cmd.exe”) in the WIN + X menu, in File Explorer”s File menu“. It does not say “[PowerShell] replaces Command Prompt“, period! The paragraph even goes on to show you how to quickly launch Cmd, and points out that you can revert this default setting to launch Cmd by default instead if you prefer. and > So, to be ultra-clear here: All that’s happening is that, in the [Win] + [X] (“Power User’s menu”), or File Explorer’s File menu, PowerShell is presented instead of Cmd. That’s all! Nothing is being removed, your scripts will continue to run just as they always have, the sky is not falling! Looks their Release Notes writer did a poor job of explaining this, so all hell broke loose and now they forced the "Commandline" Blog Team to write a blog post screaming in CAPS and with Underlined words and Big Fonts (and even more confusing language and punctuation), to tell everyone - what they really meant to say - in their release notes.
- ralish 10y agoAgree that the phrasing could have been a lot clearer, but really, Microsoft removing cmd just doesn't pass even a basic sanity check. I remember seeing the original news articles and just ignoring them as obviously rubbish. It's pretty sad to see so many tech news sites & aggregators just pick-up and run with stories like that which anyone at all knowledgeable about the subject area would immediately know is hyperbole.
- samplatt 10y agoThey implemented bash into Windows 10, and their web-ish/app-ish "platform" Silverlight does not work in their own browser in Windows 10 and isn't intended to. Microsoft have improved leaps and bounds in the last few years but saying that a story is immediately hyperbole because "X-good-technical-reason" isn't something I'm willing to commit to for any large corporation.
- ralish 10y agoSure, but the degree of usage of cmd makes Silverlight's usage look like a hobby project. It's used everywhere, including all over Microsoft's own software. It'd easily be the single biggest backwards incompatible change ever made by Microsoft and would affect software going back to the 1980s. The engineering effort involved to migrate anything that is using cmd is mind boggling, to the extent of being completely infeasible. It's a safe bet that for as long as Windows is around, cmd is going to stay with it.
- intrasight 10y agoFor C# developers, have a look at csi (C# Interpreter) as a potential cmd replacement. I've been using it extensively for a couple weeks and like it very much. Also, the same scripts can, with little modifications, be posted to Azure Functions to run on the cloud.
- intrasight 10y agoSee https://msdn.microsoft.com/en-us/magazine/mt614271.aspx https://msdn.microsoft.com/en-us/magazine/mt614271.aspx and http://www.hanselman.com/blog/InteractiveCodingWithCAndFREPLsScriptCSOrTheVisualStudioInteractiveWindow.aspx http://www.hanselman.com/blog/InteractiveCodingWithCAndFREPL...
- starik36 10y agoWow, that is pretty awesome. Is there anyway to get Intellisense into the command window for CSI? I, all of a sudden, realized that I don't remember properties of the objects without it.
- Locke1689 10y agoYou can get that in VS via the Interactive Window (View->Other Windows->C# Interactive). Theoretically you could implement a completion system for the terminal but we reused the WPF editor layers for the completion system rather than building a new one from scratch, so it isn't available in the terminal. Also, all that is open source at https://github.com/dotnet/roslyn https://github.com/dotnet/roslyn and the scripting core can be rehosted as an API.
- pjmlp 10y agoOr even better, the F# version of it (.fsx).
- rubber_duck 10y agoLast time I tried this there was no way to load nuget references. Very limited usability if that's true. I wasn't trying to use it as a shell replacement but like a REPL for interactive development/prototyping. F# works better for this IIRC but I have not used F# several years - need to brush up on it.
- majkinetor 10y agoPowershell should have been set as default years ago, particularly on core. It escapes me how windows admin community still largely ignores Powershell while clicking next in the loop. Until MS makes Windows Powershell first, adoption will change very slowly as we witnessed so far. Nano server will hopefully bring it faster. Its a terrible injustice as posh is best shell in the existence IMO. What I really want to see in future is exporting entire control pannel config as posh script. This is the perfect time to digg into it given that control panel is being transformed into 'settings'.
- josephcooney 10y agoThe horrible syntax of Powershell isn't something I can look past.
- alkonaut 10y agoI think it's fairly neat (I mean - for shell scripting not for interactive use). The problem with shells is that they want to do both. The alias system in PS tries to make it possible to use a more bash-like syntax in interactive and the verbose syntax in scripts, which is a good idea, but it's hard to get right.
- ygra 10y agoAs someone who golfs in PowerShell and very frequently uses it interactively too, I think the complaints about lack of terseness are quite overblown. Aliases, parameter binding by position or pipeline, the ability to shorten parameter names as long as they remain unambiguous, parameter aliases – all features that are most important for interactive use. Apart from a few nagging things where parameter prefixes clash (gci -f matches Force and Filter) I think it's quite good. Besides, I gladly pay that little price for much improved readability, discoverability and memorability. No more pondering whether the -Recurse flag is -r or -R in this particular command, for example.
- noinsight 10y ago
- rmm 10y agoI want to use powershell more but I am too trained to <Win+R> cmd <enter> To do the same with powershell I need to type "powershell" within run, many more keystrokes. I would love to just type "ps" or something short to do this. (natively not via an alias for when im using other peoples computers)
- jm547ster 10y agoSet up an alias for ps via .bat which then closes the cmd window - <Win+R> cmd <Enter> ps
- jm547ster 10y agoSorry didn't read to the end of your comment :)
- ygra 10y agoI have pinned PowerShell to the task bar, so on machines I use with my users it's always Win+Shift+4 to get a new instance. Win+X,i is another way (provided you enabled the option for PowerShell to replace cmd on that menu, which the article mentions as becoming the default eventually).
- EvanAnderson 10y agoThe inability to launch an elevated process with an easy key shortcut in the "Run" <Win>+<R> dialog has been breaking me of that muscle memory over last few years. The <CTRL>+<SHIFT>+<ENTER> sequence to elevate a new process works from the "Search" text-box in the Start Menu, but not the "Run" dialog.
- Semaphor 10y agoYou just made my life so much better. Right click->Run as Administrator was pretty cumbersome.
- EvanAnderson 10y ago
- MrRadiotron 10y ago> Typing “cmd” (or “PowerShell”) in File Explorer’s address bar will remain a quick way to launch the command shell at that location. Where the hell is this stuff documented?!
- gpvos 10y agoI learnt it from colleagues. Maybe it was mentioned on a blog somewhere. It's the Microsoft way!
- eptgrant 10y agoThis has just changed my life. I thought right click -> Open Command Window Here was the only way. (Sometimes need to hold shift? Maybe just in user directories)
- ygra 10y agoIt's also in the File menu.
- emmanueloga_ 10y agoOn a related note, I recently discovered WoX [1] and I'm pretty happy with it. I think it is an even more convenient launcher: Alt+Space from anywhere, type cmd, ENTER. With a couple plugins you can type things like "win <TAB>" to select from a list of open windows, "g search-term" to google a term, etc. 1: https://github.com/Wox-launcher/Wox https://github.com/Wox-launcher/Wox
- frou_dh 10y agoI was happy to find out about Clink: https://mridgers.github.io/clink/ https://mridgers.github.io/clink/ It's not a cmd.exe replacement/wrapper - it just hooks the program and beefs it up with decent stuff like Unix style keybindings, history and completions.
- TwoBit 10y ago"Cmd has served us all well for almost 30 years now" No it hasn't.
- deleted 10y ago[deleted]
- yuhong 10y agoThe name CMD.EXE actually comes from OS/2.
- SmellyGeekBoy 10y agoWhat a strange writing style! Almost every sentence ends in an exclamation point! I never realised CMD could be so exciting!
- lottin 10y ago> MS-DOS’ command-line shell’s scripting language was relatively terse and moderately powerful, but lacked many of the richer, and more advanced features we enjoy in modern-day PowerShell, Bash, etc. Nice try, but the Bourne shell, which dates from 1979, already had most of the features commonly found nowadays in Unix shells.
- Insanity 10y agoWhen I started working on Windows again at the end of last year, the first thing I did was pin PowerShell to the taskbar. I have not used the plain CMD for a long time and would not go back to it. Muscle memory makes me type "ls" in any directory I enter when looking around for something, the fact that PowerShell has this is already a reason for me to use it. I'm not a heavy PS user though, and feel that it still compares poorly to Linux or Mac's terminal for that matter.
- alkonaut 10y agoThe terminal itself is poor, but PS the language is so much more sane and ergonomic than bash. Doing text-in-text-out where the sed/awk/split/sort relies on every program in the chain (perhaps a git log, or an ls or whatever) to spit out its text in exactly the same way it always has just feels like a terrible idea. Example: count the number of files of each extension in the current direcory and list the results alphabetically by extension (I honestly didn't pick this as a way to show of PS strength and I realize that you can always pick a benchmark that shows what you want - but I wanted something small and understandable). PS: ls | group Extension | sort Name | select Count, Name bash: ls | awk -F . '{print $NF}' | sort | uniq -c | awk '{print $2,$1}' These lines accomplish the same thing, with about the same amount of typing required. You can argue that objects are brittle too, or that text is a universal format whereas objects are not. But you can't tell me the bash line looks better, or that for everyday tasks PS is always a verbose mess. Also: just typing the bash line on my keyboard includes hitting Ctrl+Alt/AltGr eleven times!
- cogs 10y agoI don't see we should have to learn a new language for this at all. The set based paradigm of SQL lends itself very well to reporting and processing files, and is known by 7 million people. SELECT extension, count(*) FROM files GROUP BY extension ORDER BY extension; We built a tool, free for personal use, that does SQL at the command line http://etia.co.uk http://etia.co.uk
- alkonaut 10y ago
- smithkl42 10y agoI use Powershell as my default command shell (via ConEmu). But its verbosity makes it a pain to work with as your everyday shell. For instance, in cmd.exe you can say: dir /od But in Powershell, you have to do: dir | sort-object LastWriteTime I totally get the Powershell verbosity when it comes to writing scripts. But it can be a PITA when you're using it interactively.
- latkin 10y agoFirst off, if you are using built-in `dir` alias, why not use the `sort` alias? Note also that you get tab completion for `dir`, `sort`, and `LastWriteTime`, so "verbosity" becomes decoupled from "speed of entering commands", which is the real goal. dir | sort LastWriteTime I think many in the "Powershell is too verbose for interactive use" camp have simply been trained by cmd to have a very narrow view of what is appropriate for interactive shell execution. Cmd's syntax and toolbox is so poor that only the simplest of tasks are considered tractable for interactive scripting - doing anything non-default is incredibly difficult (or impossible) without a dedicated flag on some windows util (e.g. `/od`). Thus you come to a state where the only commands anyone enters interactively in cmd are very short and simple - not because the language is concise but because it's too painful to attempt anything more. Translating that narrow set of cmd-suitable tasks into Powershell, one finds that indeed on average Powershell is a bit more verbose, and one says stuff like "Powershell is more verbose than cmd". What you're missing is that Powershell actually gives you a general, complete, and uniform set of tools, which really are fairly concise given their power. The space of tasks which are now suitable for interactive scripting is now vastly larger. So before you say Powershell is "too verbose", I ask how concise batch/cmd is for the following tasks: # assign earlier result to a variable (quite hilarious the gymnastics cmd makes you do simply to assign stdout to a damn variable) $x = dir | sort LastWriteTime # sort by the modified *date*, then by filename dir | sort {$_.LastWriteTime.Date},Name # get the sum of file sizes in the current dir, in MB (dir | measure Length -sum |% sum) / 1MB Many would reply to this with something like "well if I need to do something like that I'd be using C#/Python/VBS". That's my point! With powershell you have a great interactive shell for super short stuff like file copies or `dir` listings (not the case for C#/Python/VBS), but ALSO the ability to do powerful general scripting with one-liners in the shell. My "everyday shell" usage frequently covers scenarios similar to or more complex than my examples above. I am quite happy to pay a minor verbosity tax on the trivial commands so that I have the power to do the non-trivial stuff without leaving the shell.
- joe563323 10y agoThe recent trend is to use the git shell on windows and execute bash scripts.
- basdevries 10y agoAt least PowerShell is taking over as the default. Should have been changed back in Windows 7. Copy & paste with Ctrl-C and Ctrl-V is what made me switch to PowerShell.