How to run C# console app using powershell

18.3k views Asked by At

I have a C# console application that reads .csv files. I want to run this in the middle of a powershell script. What is the best way to do this?

3

There are 3 answers

0
Dan Field On BEST ANSWER

Use Start-Process, perhaps with the -PassThru option, for example:

$csvProc = Start-Process my_csv_reader.exe -PassThru

This would allow you to do something like $csvProc | Stop-Process later on, or to check if it's still running at a later point in your script through $csvProc.HasExited

If you need even more control, you could do it this way:

$csvProc = New-Object System.Diagnostics.ProcessStartInfo

and then you can use $csvProc the same way you'd use ProcessStartInfo in C# (setting the file name, paramaters, redirecting standard in or out, starting the process, etc.).

0
cjones26 On

Easy:

Start-Process -Wait PathToFile

If you don't want to wait for the process to finish remove the "-Wait" switch.

0
Rikard Söderström On

If your executable isn't in your path you will need to tell powershell where to find it.

& "c:\some path with spaces\foo.exe" <arguments go here>

This has been answered before, here: Executing an EXE file using a PowerShell script