user9739096
user9739096

Reputation:

how to send specific output value from exe (c#) to power shell script

Now I'm creating a vsts build task, my approach is:

My issue is:

Not sure if the script code helps but here it is

$psi = New-object System.Diagnostics.ProcessStartInfo 
$psi.CreateNoWindow = $true 
$psi.UseShellExecute = $false 
$psi.RedirectStandardOutput = $true 
$psi.RedirectStandardError = $true 
$psi.FileName = "app.exe"
$process = New-Object System.Diagnostics.Process 
$process.StartInfo = $psi 
[void]$process.Start()
$output = $process.StandardOutput.ReadToEnd() 
$process.WaitForExit() 
then process the output

Upvotes: 2

Views: 67

Answers (2)

Bruce Payette
Bruce Payette

Reputation: 2639

The ability to run executables as commands is built into PowerShell. To run app.exe and capture its output, all you have to do is

$output = app.exe

PowerShell takes care of all the underlying process management.

Upvotes: 1

Tony
Tony

Reputation: 17657

If you want something more complex you can interop directly with the assembly, instead of using an EXE

[System.Reflection.Assembly]::LoadFile("E:\MyClass.dll")
$MyCompObj = New-Object MyClass.Student

See:
how to call my dll and use it in powershell script
https://winscp.net/eng/docs/library_powershell

Upvotes: 0

Related Questions