2

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

  • Run powershell script
  • Inside the powershell, I'll run the exe or dll
  • Then use the output to extract the value.

My issue is:

  • I do a lot of printing, and I'll print my value at the end and add some delimiter to be able to extract it
  • but I feel like it's a bad design I'm not expert in powershell scripting but
  • if anyone has a better design please let me know

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
1
  • I'm voting to close this question as off-topic because "My code works but could the design be better?" is off-topic for StackOverflow and on-topic for codereview.stackexchange.com Commented Jun 20, 2018 at 3:48

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.