Skip to content

Instantly share code, notes, and snippets.

@ross-g
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ross-g/38696ac49da9ee0d8d4a to your computer and use it in GitHub Desktop.
Save ross-g/38696ac49da9ee0d8d4a to your computer and use it in GitHub Desktop.
Using dotNet "System.Diagnostics.Process" for a better DOSCommand in Maxscript.
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