alberto wrote:
How can I execute a command of the operating system like "cls" from a C#
code?
Thank you
To execute normal program files (.exe, .com, etc.) you just use
System.Diagnostics.Process.Start("test.exe") (look in the Process class
there, more ways to do it than just .Start(programname)).
However, CLS, DIR, etc. are internal commands for the command shell and
to execute them you need to do it through the command shell executable.
For NT-based operating systems, do:
CMD.EXE /C DIR
for Win9x, do:
COMMAND.EXE /C DIR
You can probably find the right name of the program to execute by
looking in the environment variables, look for the COMSPEC variable.
Example:
System.Diagnostics.Process.Start(Environment.GetEn vironmentVariable("COMSPEC"),
@"/C DIR C:\ >C:\test.txt");
System.Diagnostics.Process.Start(@"NOTEPAD.EXE", @"C:\TEST.TXT");
--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2