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?
How to run C# console app using powershell
18.3k views Asked by Cj_wink17 At
3
There are 3 answers
0
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
Use
Start-Process
, perhaps with the-PassThru
option, for example: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:
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.).