[Closed] Inconsitent results between Windows versions with System.Diagnostics.Process
So I’m trying to run processes through command line and hopefully get back the output.
This snippet right here works for me on Windows 7. It runs “cmd.exe” and uses “VER” as an argument to get back the Windows version. Keep in mind this is just an example, I’ll obviously use this with other exe files.
This snippet runs as expected; the dos command window flashes briefly and the output is printed to the listener.
However…I’ve tried it on 2 different Windows 10 PCs and in both cases the Command line window stays black an opened. Maxscript won’t continue until the window is manually closed.
Is this a bug? or am I missing something?
fn run exe_path arg_array 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 = ""
--process.StartInfo.CreateNoWindow = true;
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 "
")
else return (filterString _output "
" splitEmptyTokens:false)
)
else
(
if as_string then return (trimRight _error "
")
else return (filterString _error "
" splitEmptyTokens:false)
)
)
run "C:\\Windows\\system32\\cmd.exe" #("VER")
EDIT: I don’t need to know if it has executed or not. I mean, of course I do. That’s the exit code, but I do need to know what the process has printed to the console. HiddenDosCommand does not provide that, this is the reason why I’m building a Process through dotnet. And I’m faced with this problem that I only experience in Windows 10