Programming a terminal emulator, what's in it? - windows

This is related somewhat to this question about a better shell terminal/gui-interface for cmd.exe
In my quest to find a better shell terminal, the only useful thing I came across was Console2, other alternatives weren't free and generally didn't offer much more than Console2 to make them worth their price.
I can't help but wonder, "how come"? The shell terminal is a very valuable tool to a programmer, yet no one came around to try and do a better job than cmd.exe (except for the guys # console2)??
Surely designing a command line shell terminal emulator can't be such a hard task!
Has anyone tried writing a shell terminal emulator before? What's in it? Any resources out there (say, if I want to program my own shell)?
UPDATE
17/07/2009
I rephrased the question, what I was referring to as a "shell" is actually called a terminal emulator (at least in the linux world). I only realized this recently so I thought I should revisit this question and fix it.

There are plenty of shells around for Windows, bash under Cygwin is the one I use the most, and it's certainly free. I have to be honest here, cmd.exe has come a long way since the batch file processor of MSDOS. It's actually quite powerful, but still not a pimple on the rear end of bash :-).
You should try to write a command line shell, it will be an education for you. It's not that hard to do the basics if all you want is a program launcher.
But, if you want all the power of a real shell, including a full blown programming language, job control, piping, output redirection and (seriously) too many other things to list, we probably won't be hearing from you for a while. Except when you pop up your head to ask us esoteric questions about how shells should do this or that.

What about PowerShell from Microsoft? AFAIK it's free, and gives you C# power right in the shell, and tons of other features. But, it DOES require the NET Framework...
I won't endorse it yet, as I haven't really used it, but it's on my list to do...

My bets are on Powershell for the future if you are a Windows guy.
PowerShell will be installed by default on Windows Server 08 R2 (WS08R2) and Windows 7 according to MS.
I have used Powershell myself and found it to be very useful, and if you are familiar with .NET then its all the more easier.
Download a two page reference document here, this is all you will need to get started.

I mean the gui-interface part that displays the text,
Ah! you mean what we call a "pseudo-tty" or a "terminal emulator" in unix. In windows, I guess it is called a "console host". I do not use windows, but I heard that console2 is very good.
Seems there are others:
http://www.powershellanalyzer.com/
http://powershellide.com/
http://www.codeplex.com/PoshConsole
and, of course, for real programmers, you have the shell mode of (x)emacs :-)

Erm... what about all the ports of Unix command shells to Windows?

Just go with cygwin and log on using PuTTY. So much better than the standard console. :)

Also, Python (or perl for that matter) can replace the shell entirely.

You might want to try Take Command Console, formerly 4NT, formerly 4DOS.
Quick summary of points you might care about:
Command line editing with filename completion, history, and cut & paste
Integrate PERL, Ruby, REXX, Python, and any Active Scripting language
Fast - 20-200% faster output display than the standard Windows console
Integrated file explorer - examine directories, drag and drop files
Upwardly compatible with CMD.EXE with literally thousands of additions
Not free (except trial version) and not open source. I haven't tried it myself, but I was a 4DOS junkie back in the day, before Cygwin.

If you need handy terminal - give a try to ConEmu (I'm the author). It is a Windows console window enhancement (local terminal emulator), which presents multiple consoles and simple GUI applications as one customizable tabbed GUI window with dozens of features.
Another answer and comments

Related

win cmd.exe in Vim tab

I'm looking for Vim/gVim plugin to use Windows shell (cmd.exe) (executing commands, retrieving output) in separate tab/frame.
There are a lots of such solutions for Linux, but I'm unable to do it in Win...
Unlike Emacs, Vim is an editor, not an environment (thank Gawd :) and it is not (nor will ever be, according to what the developers have been saying for the past 20 years) designed to house a command prompt/shell in one of its buffers.
That being said, there are a couple of plugins that try to imitate that functionality. Some work better, some worse ... check'em out, and see what works best for you:
cmd.vim
Shell.vim
Conque
Just to add, I don't use any of the above - just found them on vim.org, so you're on your own from here on.

PowerShell eye for the Bash guy

For someone who has been using bash for years, what's the quickest way to get productive with Microsoft's PowerShell? I've noticed my old friends ls and ps work, but sadly grep didn't. I could just man up and read through the piles of documentation, but I'm guessing there is a quicker path to productivity for someone with a long history of bash usage.
I don't know if it matters or not, but the reason I'm looking to get acquainted is because it seems like there is finally a proper shell on Windows instead of needing to install cygwin, and I'd like to start using it exclusively instead of writing bat files for automated activities like builds and deployments and such.
I'm not sure your Bash history is going to help you much with PowerShell. It is quite a bit different since the idea is to pipeline rich .NET objects as opposed to text or byte streams. For a leg up, check out my Effective PowerShell free eBook. It is about 60 pages but I think does a decent job of outlining the mental model you need to get the most out of PowerShell. For a full, free book check out Master PowerShell. At the point you think you're willing to part with some $$, Windows PowerShell in Action is the best book out there IMO.
Note: there are some "Unix" oriented aliases to get you by for a while (ls, ps, etc) but you'll run out of steam pretty quick because the parameters are quite different and as I said the pipeline is quite different than in Bash.
I would also recommended looking over some of the Q&A on PowerShell on StackOverflow especially for those questions that you think - "yeah, how would you do that in PowerShell". I think you would learn a good bit just doing that.
A quick Cheat sheet
​​​​​​​​​​​
I'd suggest just man up and read through the "piles" of documentation. It's actually not that difficult once you get the basics down. You'll need the knowledge anyway if you intend to do anything even remotely productive with PowerShell.
there GNU utilities such as your favourite grep that is ported to windows. see GNU packages
on the other hand, if you loathe the idea of downloading stuff, you can use vbscript. it comes natively installed.

Resources To Learn About Batch Files

In my new project I need to use batch files(many of them), but now I need to know about they and where can I read some good tutorials to use they very good ;)
PS: I need to distribute my application for end-users.
Well, learning by doing is probably the best way. There are many pitfalls and weirdnesses in the batch language, making some tasks very much non-fun to do. But I think one should at least stepped into each trap once :-)
References are for example (sometimes with extensive examples for specific usage scenarios):
Rob van der Woude
SS64
Technet
Specific problems and solutions may be found on sites like Rosetta Code but there aren't many (and I still didn't get around cleaning up there; the batch examples are horrible). I maintain a few tricks on my own site as well (currently under maintenance, though; struggling with my syntax highlighter).
Others have mentioned it: If you have the option, then by all means use other technologies. PowerShell is a nice one but not included by default on older Windows systems, including Vista. For many more complex tasks VBScript via WSH is usually a better option as it has a similar installed base and is way more powerful.
Depending on your requirements this may or may not be possible, but take it into consideration if it may be an option.
While I usually don't like MSDN, in this case its documentation on batch files seems fairly decent.
Basically with bat/cmd files you are running DOS commands (with extra programs/features available to Windows) with each command on a new line.
The .cmd extension is prefereable to .bat on older Windows systems as it runs with cmd.exe, which executes faster than the older command.com. On newer systems (XP and above I think) then it doesn't matter if it is .cmd or .bat then they get executed by cmd.exe.
Here's some tips/examples on writing batch files:
http://www.ericphelps.com/batch/
Wikipedia has a list of DOS commands here:
http://en.wikipedia.org/wiki/List_of_DOS_commands
Here's some info on invoking the actual cmd.exe
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
You can start with: Command Line = PowerShell / bash / zsh / ...
Batch is very old-fashioned and practically obsolete now.
The one thing I can recommend if you're working with batch scripts in Windows is learn PowerShell. It's a souped up command line that will allow you to interact with any .net object.
Have fun!
Besides everything that was suggested, I can recommend using VBScript (.vbs). To use Powershell, you need to install it (although it might be installed along with Windows Updates). To use VBScript (which is also very powerful) you don't need anything, it's in Windows by default.
On Windows, use Start|Help and Support Center, and search on "Using batch files", and then in the list of topics under "Overviews, Articles and Tutorials" in the Suggested Topics, click on "Batch files". You'll find links to using parameters, filters and redirection, as well as reference links for batch commands like CALL, ECHO, FOR, and so forth.
The one advantage of batch files over PowerShell is that PowerShell may not be installed, while the command processor (CMD.EXE, or the older DOS version COMMAND.COM) will definitely be there.

What tools and languages are available for windows shell scripting?

I want to know what are the options to do some scripting jobs in windows platform.
I need functionality like file manipulations, registry editing etc. Can files be edited using scripting tools?
What other functionality does windows scripting tools offer?
Can everything that can be done using the Windows GUI be done using a scripting language?
I think Windows PowerShell from Microsoft is the current favourite for this sort of thing.
It might be worth looking at the prerelease of version 2.0. A lot of stuff has changed:
http://blogs.msdn.com/powershell/archive/2007/11/06/what-s-new-in-ctp-of-powershell-2-0.aspx
How about installing a windows version of Python, Perl or your favorite language? These should offer all the functionality you need.
Batch files are the most portable, but doing complicated things can get hard (very hard).
Powershell is incredibly - um - powerful, but the installed domain at the moment is only slightly more than those people who like using powershell and servers they administer. If you control the machines you're scripting on and can mandate that powershell is installed, powershell is the way to go. Otherwise, batch files are the best way.
Powershell lets you do anything which can be done, but some things will be harder than others :)
(Seriously, if you want to control a windows GUI app from a script, you're going to have a lot of pain unless the app supports scripting itself, or you want to start posting messages to dialog controls and screen scraping the dialog to check for success.)
I would recommend "Take Command" (JPSoft), which is more like "cmd.exe" than the PowerShell. We use here at ESSS for years.
Windows Scripting Languages
Also take a look at PowerShell
CScript ? I remember seeing something like that.
Powershell is nice, but it's an extra thing you have to install. Not standard in almost any windows installation. So, if it's just for your own use, then powershell should be fine. If you need the scripts to run on the computers of the general population, for instance, as part of a piece of software you are producing, it may not be the best option.
If you are ok with an extra thing you have to install, you might want to check out cygwin. This allows you to have a full Linux bash command line and all the associated tools at your disposal.
If you need something included in a default windows install. There's the windows command line (cmd.exe). Which has some functionality, but is very deficient compared to what's available in Linux. The other, probably worse problem, is that there isn't much out there in the way of documentation.
You might also be interested in VB Script (flame away). VB Script should work on almost any recent standard windows install, and is a lot more functional than the command line.
I have cygwin installed, so I can run bash shell scripts for my automatization needs. Besides, when I need stuff running moreless natively on Windows, I use a combination of batch + jscript (runs on cmdline if you have Visual Studio.Net installed, just call "cscript XXX.js").
Scripting is a blast.
Personally I like to write some evil little batch files. You can find a command line program to do just about anything. I prefer Batch files mostly because they are portable from one machine to another with at most a zip with a few unix tools (SSED, GREP, GAWK). there is a commandline REG.Exe that can even do Registry changes and reads. You can parse output from commands with a "FOR /f" loop.
PowerShell does have more... err.. Power (2nd post I wrote that in, but I can't help it.)
If you want to look at windows automation check out AutoHotKey.
What are you trying to automate? That may help us narrow down what would be helpfull.
Josh
EDIT: for the record I typed that at the same time as #jameso If someone at work hadn't asked me a question, I may have posted before him. I did get a bit of a shiver at the similarity of the post though....
Powershell can do what you need.
file manipulations
This SO post answers how you can replace a string in your text file. Pasting it here for easy reference:
(Get-Content c:\temp\test.txt).replace('[MYID]', 'MyValue') | Set-Content c:\temp\test.txt
There are other things that you can do, such as copying files and folders. You can find out more on the Windows Powershell Documentation
registry editing
This can be easily done using Powershell. Here's a sample code from Microsoft Dev Blogs:
Set-ItemProperty -Path HKCU:\Software\hsg -Name newproperty -Value anewvalue
Yesterday I could have repaired this for you ;)
What all are the tools/languages for
windows shell scripting?
Would read better as
What tools and languages are available
for windows shell scripting?

Where can I find a graphical command shell?

Terminals and shells are very powerful but can be complicated to learn, especially to get the best out of them. Does anyone know of a more GUI based command shell that helps a user or displays answers in a more friendly way? I'm aware of IPython, but even the syntax of that is somewhat convoluted, although it's a step in the right direction.
Further to this, results could be presented graphically, e.g. wouldn't it be nice to be able to pipe file sizes into a pie chart?
Hotwire is an attempt to combine the power of the traditional command line interface with GUI elements. So it has a GUI side, and tries to be helpful in suggesting commands, and in showing you possible matches from your history. (While there are keyboard shortcuts to do this in bash and other shells, you have to know them ...)
You can use all your common system commands, but a number of key ones have new versions by default which use an object pipeline, and are displayed with a nice GUI view. In particular ls (aka dir) shows lists files and shows them in columns. You can sort by clicking on the column headers, double click on files to open, or double click on directories to move to that directory. The proc command allows you to right click on a process and one of the options is to kill it.
The object pipeline works in a similar way to Microsoft Powershell, allowing commands in the pipe to access object properties directly rather than having to do text processing to extract it.
Hotwire is cross platform (Linux, BSD, Windows, Mac), though it is at an early stage of development. To learn more, install (click on the link for your platform) and work through the simple getting started page.
If you don't like hotwire, you could also look at the list of related projects and ideas maintained on the hotwire wiki.
fish is a Unix shell that focuses on user-friendliness, such as by providing colored highlighting and extensive tab completion.
For a different kind of blend of textual and graphical interface, there's Quicksilver, as well as similar/inspired tools like Launchy, GNOME Do and ENSO.
Is this for Python in particular, or are you just interested in any command shell that has a GUI interface?
If the idea of piping file sizes into a pie chart interests you, you might try PowerGUI, a GUI layer on Microsoft's PowerShell command shell. PowerShell also lets you pipe data from commands into XML, CSV, and other formats that are understood by GUI programs.
GUI-based command shell seems like an oxymoron to me.
Not really? A command shell is just an encapsulated environment in which to execute commands. Why can't they have GUI extensions? We are in the 21st century! :)
Check out http://hotwire-shell.org/
This is along the lines of what I was thinking. It's a shame it uses PyGTK, I'd have preferred PyQT (perhaps a licensing issue?). There look to be some interesting related links from the project as well.
If the idea of piping file sizes into a pie chart interests you, you might try PowerGUI, a GUI layer on [...]
PowerGUI looks like a hobby project I've been working on that organises regularly used tasks. It looks like it organises frequent jobs and formats the output for you. The formatting I see as the end result of the data flow. But it would be nice to be able to tinker with data and then continue to use it.
PowerShell as a command shell is very forgiving for new users and is easy to learn. There is an add-on product (it is a commercial product) called PowerGadgets that would let you pipe file sizes into a pie chart or other types of displays
PowerGadgets looks very interesting. It would be interesting to have things like system monitors so that you could say, read the CPU usage per second and pipe it into a graph.
Is this for Python in particular, or are you just interested in any command shell that has a GUI interface?
Any really, currently, but I like the idea of cross platform, easy to edit, no compiler setup. I use Windows at work and Windows/Linux (Ubuntu)/OSX at home. Python is just an easy solution, and for writing stuff like this is has a lot of libraries already.
Thanks for all the links. Keep them coming. :)
I'm not sure whether you're asking for a shell as in bash/csh, or a shell as in ipython. If it's the later, then I'd recommend looking at Reinteract. While it's still very alpha, it's already a great tool for rapid prototyping in python, and allows embedding of plots, widgets, etc.
GUI-based command shell seems like an oxymoron to me.
The key-word here is Graphical.
If I want a GUI, I want a full-featured GUI. But if I want raw performance, I want a command line.
I'm not exactly sure what you're asking for. You can either have a GUI or a command line. What do you need from a graphical command shell that you couldn't get from a straight GUI?
Also, if you want graphical information about file sizes there are a few applications that do that. One example is WinDirStat.
Also not related to Python, but Ubiquity (a firefox extension) is a graphical command-line-like tool for the web, with a similar spirit to Quicksilver/Launchy/GnomeDo.
I know that Automator in Mac OS X is not a shell but it is the best graphical tool I have ever used to do batch tasks. I think it is worth mentioning here as even I (self-titled as a power user) use it from time to time to rename files or other routines. Although these could be done in a few lines of shell script, the Automator's graphical interface makes me feel like I am not working and it just works.
Check out http://hotwire-shell.org/
PowerShell V2 is developing a graphical command shell, but I don't think that is what you are looking for.
PowerShell as a command shell is very forgiving for new users and is easy to learn. There is an add-on product (it is a commercial product) called PowerGadgets that would let you pipe file sizes into a pie chart or other types of displays. Information about that can be found here.
As for ease of use, PowerShell command follow a Verb-Noun pattern (along with aliases for ease of use from the command line) and is very discoverable. Check out some screencasts I did on using PowerShell at PowerShell Basics.
I found POSH, a GUI for MS PowerShell. This is pretty much what I intended. You have a command-line backend with a WPF GUI frontend. You can pipe results from command to the next and show graphical output.
Maxima provides a mathematical shell (screens) . It is nice that you type in a C-like syntax and receive graphically formatted output.

Resources