Notifications
Clear all
[Closed] standardOutput.ReadToEnd encoding
Sep 16, 2018 12:24 am
global Dos_Command
struct DOSCMD (
fn run exe_path arg_array:undefined as_string:false =
(
local process = dotNetObject "System.Diagnostics.Process"
process.StartInfo.UseShellExecute = false
process.StartInfo.RedirectStandardOutput = true
process.StartInfo.RedirectStandardError = true
process.StartInfo.FileName = exe_path
process.StartInfo.Arguments = ""
if arg_array != undefined then
(
for arg in arg_array do (process.StartInfo.Arguments += (" " + arg as string))
)
process.Start()
process.WaitForExit()
local _output = process.StandardOutput.ReadToEnd()
local _error = process.StandardError.ReadToEnd()
process.Close()
process.Dispose()
if _error == "" then
(
if as_string then return (trimRight _output "\r\n")
else return (filterString _output "\r\n" splitEmptyTokens:false)
)
else
(
if as_string then return (trimRight _error "\r\n")
else return (filterString _error "\r\n" splitEmptyTokens:false)
)
)
)
if Dos_Command == undefined then Dos_Command = DOSCMD()
Hello!
I’m using this code to get command line tool output in max. But it has some problem with character encoding or dotnet string conversion to max, I’m not sure.
Take a look in screenshot, in Max I have wrong symbols. It seems when string come to Max some symbols was convert from /a to BEL symbol, but I cant figure how to fix it.
I tried force use cli encoding as 850 but it doesn’t helps.
process.StartInfo.StandardOutputEncoding = (dotNetClass "System.Text.Encoding").GetEncoding(850)
Can any one help me?