1

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?

Cj_wink17
  • 45
  • 1
  • 1
  • 4
  • 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 Answers3

3

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
  • 1,000
  • 6
  • 14
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
  • 20,885
  • 5
  • 55
  • 71
1

Easy:

Start-Process -Wait PathToFile

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

cjones26
  • 3,459
  • 1
  • 34
  • 51