8,330 questions
I found this... add one of these lines and see if you get different results.
$pinfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
or
$pinfo.StandardOutputEncoding = [System.Text.Encoding]::Unicode
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi. I have code powershell:
$DisableACMonitorTimeOut = Execute-Command -commandTitle "test" -commandPath "C:\Program Files\MyProgram\file.exe" -commandArguments "-help"
$DisableACMonitorTimeOut.stdout
Function Execute-Command ($commandTitle, $commandPath, $commandArguments)
{
Try {
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $commandPath
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.WindowStyle = 'Hidden'
$pinfo.CreateNoWindow = $True
$pinfo.Arguments = $commandArguments
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
$p.WaitForExit()
$p | Add-Member "commandTitle" $commandTitle
$p | Add-Member "stdout" $stdout
$p | Add-Member "stderr" $stderr
}
Catch {
}
$p
}
How i can got output in UTF8 ?
I found this... add one of these lines and see if you get different results.
$pinfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
or
$pinfo.StandardOutputEncoding = [System.Text.Encoding]::Unicode
UTF8 not work for me, instead, I use next:
$pinfo.StandardOutputEncoding = [System.Text.Encoding]::GetEncoding(866)
https://stackoverflow.com/questions/16803748/how-to-decode-cmd-output-correctly/26015551#26015551