Reputation: 3564
I am new to C#, and I am trying to call 'cls' command using the following:
Process.Start("cls");
When i execute this line the program halts. If I switch 'cls', lets say to 'notepad' the progam works properly. Why is that?
Thanks, Sun
Upvotes: 1
Views: 60
Reputation: 19981
It's trying to execute a program called cls
. Is there such a program? (If you're thinking of the cls
command you have in a command window, that isn't a separate program, it's a command implemented inside the cmd
program.)
Upvotes: 0
Reputation: 14784
It does not work because cls
is not a process that can be started (in contrast to notepad), but a command of the command prompt. What are you trying to achieve?
Upvotes: 0
Reputation: 1062965
Notepad is an actual exe; cls is a command to the interpreter, not an exe. You can probably "fix" it by toggling use-shell-invoke, but either way, it won't help because it isn't clearing your console window, but the console window of the newly spawned process.
I suspect you want:
Console.Clear();
Upvotes: 4