#NEWLINE# def Popen_with_delayed_expansion( cmd , * args , **kwargs ) : #NEWLINE# #INDENT# "\n    A thin wrapper around subprocess.Popen which ensures that all environment variables in the cmd are expanded at\n    execution time. By default, Windows CMD *disables* delayed expansion which means it will expand the command first\n    before execution. E.g. run 'set FOO=1 && echo %FOO%' won't actually echo 1 because %FOO% gets expanded before the\n    execution.\n\n    :param cmd: The command to execute\n    :type cmd: str | iterable\n\n    :return: Popen object, just like the Popen object returned by subprocess.Popen\n    :rtype: :class:`Popen`\n    " #NEWLINE# if is_windows ( ) : #NEWLINE# #INDENT# cmd_with_deplayed_expansion = [ 'cmd' , '/V' , '/C' ] #NEWLINE# if isinstance ( cmd , str ) : #NEWLINE# #INDENT# cmd_with_deplayed_expansion . append ( cmd ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cmd_with_deplayed_expansion . extend ( cmd ) #NEWLINE# #UNINDENT# cmd = cmd_with_deplayed_expansion #NEWLINE# #UNINDENT# return subprocess . Popen ( args , * args , ** kwargs )