Reputation: 4016
I never studied OSes, so forgive me if this sounds basic or silly, but I'm curious about if one could replace the cmd prompt in Windows. I am NOT asking for programs that actually do this, as I've looked around and not really seen any.
What I'm asking is 1) if it's actually possible to write an entirely new program that would behave like cmd and 2) if one could then replace cmd with it, assuming it could perform at least all the jobs that cmd does.
Because it seems like even programs that claim to be an upgrade to it (cygwin, powershell, etc) are actually running in that same little black window. Maybe I'm just not fully understanding how cmd fits into windows as a whole, or how something like bash actually connects into linux.
Anyone care to steer me in the right direction?
Upvotes: 3
Views: 1185
Reputation: 4555
you could write an application that allows you to create and execute batch (.bat) files.
for example, let's say you use C# as your language. you can open a text stream to create the (.bat) files. then, you can execute them like this:
ProcessStartInfo CmdReplacement = new System.Diagnostics.ProcessStartInfo();
//choose a name and then arguments that you want to send to the command prompt
CmdReplacement.FileName = @"C:\testfile.bat";
CmdReplacement.Arguments = "1 2 3 4";
//if you use this property it will prevent a console window from popping up
pi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//create new process and set starting information
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = CmdReplacement;
//set this to tell you when the process has completed
p.EnableRaisingEvents = true;
p.Start();
//wait until the process has completed
while(!p.HasExited)
{
System.Threading.Thread.Sleep(1000);
}
//check to see what the exit code was
if(p.ExitCode != 0)
{
//some error occurred
}
Upvotes: 1
Reputation: 66709
This might help you lead on alternative command shells that can be used on windows :) CMD.EXE is just a program that provide CLI interface. There are in fact good alternatives.
Upvotes: 2
Reputation: 86506
"That same little black window" is a feature of Windows's "console" subsystem. Console-mode apps get that window pretty much for free, and have it opened for them (either by Windows itself or by the runtime libs, i forget which) when they're started from Windows rather than from the command line. (Console-mode programs run from an existing console tend to borrow the console of the parent process.)
The fact that console apps look alike doesn't necessarily mean they're all run from cmd.exe (although there's often a batch file that starts them, they can be started on their own), but that they all use the same subsystem and the same features.
With all that said, it's quite possible to write a replacement for cmd.exe. It's just a console app. The catch is making it compatible enough to run batch files (lest existing apps break when they expect to use cmd.exe), and still having enough flexibility to add whatever you want to add to a shell.
Upvotes: 4
Reputation: 161773
CMD.EXE is just a program. There's nothing special about it.
Upvotes: 0