Last active
August 29, 2015 14:26
-
-
Save ross-g/38696ac49da9ee0d8d4a to your computer and use it in GitHub Desktop.
Using dotNet "System.Diagnostics.Process" for a better DOSCommand in Maxscript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment