Sunscreen
Sunscreen

Reputation: 3564

Unhalted error by system call

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

Answers (3)

Gareth McCaughan
Gareth McCaughan

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

Florian Greinacher
Florian Greinacher

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

Marc Gravell
Marc Gravell

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

Related Questions