Revision 2557ff82 lib/utils.py

b/lib/utils.py
102 102
  output = property(_GetOutput, None, None, "Return full output")
103 103

  
104 104

  
105
def RunCmd(cmd):
105
def RunCmd(cmd, env=None):
106 106
  """Execute a (shell) command.
107 107

  
108 108
  The command should not read from its standard input, as it will be
......
110 110

  
111 111
  @param cmd: Command to run
112 112
  @type  cmd: string or list
113
  @param env: Additional environment
114
  @type env: dict
113 115
  @return: `RunResult` instance
114 116
  @rtype: RunResult
115 117

  
......
125 127
    strcmd = cmd
126 128
    shell = True
127 129
  logging.debug("RunCmd '%s'", strcmd)
128
  env = os.environ.copy()
129
  env["LC_ALL"] = "C"
130

  
131
  cmd_env = os.environ.copy()
132
  cmd_env["LC_ALL"] = "C"
133
  if env is not None:
134
    cmd_env.update(env)
135

  
130 136
  poller = select.poll()
131 137
  child = subprocess.Popen(cmd, shell=shell,
132 138
                           stderr=subprocess.PIPE,
133 139
                           stdout=subprocess.PIPE,
134 140
                           stdin=subprocess.PIPE,
135
                           close_fds=True, env=env)
141
                           close_fds=True, env=cmd_env)
136 142

  
137 143
  child.stdin.close()
138 144
  poller.register(child.stdout, select.POLLIN)

Also available in: Unified diff