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?
Asked
Active
Viewed 1.5k times
0
-
http://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx – Mike Jun 12 '15 at 19:21
-
Thank you for the responses everyone. I'm new to this stuff so sorry for the duplicate question. I tried looking but couldn't find an answer to my question. Cheers! – Cj_wink17 Jun 12 '15 at 19:50
3 Answers
2
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.).
Dan Field
- 19,501
- 3
- 49
- 69
1
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
Community
- 1
- 1
Rikard Söderström
- 870
- 6
- 14
0
Easy:
Start-Process -Wait PathToFile
If you don't want to wait for the process to finish remove the "-Wait" switch.
cjones26
- 3,321
- 1
- 30
- 45