user1016179
user1016179

Reputation: 629

Convert power shell script to C#

I have a script in Power Shell which runs a process of Microsoft and would like to convert it to C# but did not find how to do it.
The line is as follows:

start-process -FilePath "telnet" -ArgumentList "-t ANSI 127.0.0.1 %Port" -Wait

This should run Windows Telnet.
How can I convert it to C#?

Upvotes: 0

Views: 887

Answers (3)

bitbonk
bitbonk

Reputation: 49619

var p = Process.Start(@"C:\windows\sysnative\telnet.exe", "-t ANSI 127.0.0.1 %Port");
p.WaitForExit();

Upvotes: 1

Dan Puzey
Dan Puzey

Reputation: 34198

A quick & dirty solution would be this:

var process = Process.Start("telnet", "-t ANSI 127.0.0.1 %Port");
process.WaitForExit();

Upvotes: 1

Richard
Richard

Reputation: 109005

Look at the System.Diagnostics.Process.Start method. For more advanced scenarios (eg. directing standard input) you'll need to pass a System.Diagnostics.ProcessStartInfo instance.

To wait for the process to exit either use the WaitForExit method (which will block) or the Exited event.

Upvotes: 0

Related Questions