jobinusa
jobinusa

Reputation: 1

Console Application Output to text file using PowerShell script

I have a written a console application. Now I have a requirement to run that console application through Power-Shell script and copy the copy the console application output to a text file. I am able to access the application through Power-shell script, but unsuccessful in copying the output to the text file. I am very new to this Power-shell scripting,

My PowerShell Script so far I had written

[string]$param1
[string]$param2
[string]$exePath = "\\Visual Studio 2015\Projects\PowerShellTestApp\PowerShellTestApp\bin\Debug\PowerShellTestApp.exe"
$psi= New-Object System.Diagnostics.ProcessStartInfo $exePath
$param1 = Read-Host "Please enter your Name"
$param2 = Read-Host  "Please enter your Location"
$psi.Arguments = $param1, $param2
[System.Diagnostics.Process]::Start($psi)

Upvotes: 0

Views: 153

Answers (1)

ATek
ATek

Reputation: 825

I don't have the exact same situation to test with but you could try the last lines to be something like follows.

 $result = $([System.Diagnostics.Process]::Start($psi))
 Out-File -InputObject $result -FilePath "C:\somelocation.txt"

Upvotes: 1

Related Questions