Run the DOS command in .NET.

I have a set of commands like:

C:
cd Project
testproj.exe

My system receives these commands one by one from the remote system. I need to execute each command in cmd.exe when receiving a command from a remote system. How to execute them using .NET?

I also need to return the result of testproj.exe to the remote computer. How to get the result after running the command?

+3
source share
5 answers

Process.Startcmd.exe and connect StandardIn, StandardOut and StandardError. Then, when the command arrives, just write it in StandardIn and read StandardOut / Error to return. All this should not exceed 15 LOC.

, Telnet, , - , ....

+6
var process = System.Diagnostics.Process.Start( "testproj.exe" );
process.WaitForExit();
var result = process.ExitCode;

, "C:" "CD-". , .

+5

System.Diagnostics.Process. stdout/stderr -, .

+4

C: cd Project Lanching Directory, SetCurrentDirectory. strong > .

, testproj.exe.

+1

, DOS, , , . Do not allow DELETE, RD, FORMAT ..

, DOS. , , .

, - , / .

UPDATE: the implementation of certain commands is provided to you. You can use the .NET API or have System.Diagnostics.Process

+1
source

Source: https://habr.com/ru/post/1714450/


All Articles