Maya Python - subprocess call without flashing cmd window


I may have to use some cmd commands to get info about the system like HID or MAC reliably, for which I am trying to use subprocess.check_output, as the easiest way. However the problem I get on Windows is that this call always makes a black cmd window pop up for a moment. This is something that would be very annoying to have on each startup of any tool, or like in general.

Is there any way of executing shell\cmd commands in Maya from Python on windows without making that black window pop up?

Or maybe there are alternative ways of getting unique hardware ID from current system and getting a MAC from a certain LAN IP?

I think adding shell=True or omitting it (one or the other) will keep Maya from popping up the window.
I’ve also got some code somewhere that should do it.
I can dig that up if using (or not using) that flag doesn’t work for you.

Oh… Yeah that did the trick, thanks :smile:

Any chance you may also suggest some of the good and proven ways of getting hardware ID of the current machine the script as running and mac\ID of a machine by IP? :smiley:

Use shelljob. Haven’t looked back since I added it to our libs:

If you need more control over hiding the window, the flag I think bob is referring to:

    if == 'nt' and hide_window:
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        win_kwargs['startupinfo'] = startupinfo
    handle = subprocess.Popen(cmd,
1 Like

Thanks. Actually just subprocess.check_output(cmd, shell=True) did the trick for me, but thanks for Popen version, it may sure come in handy too!

And I can’t really use external packages, not in a clean way anyway, as it’s for distribution, no shelljob :frowning: