def Run(self, command, timeout=None, env=None):
"""Run a command against this SDK installation.
Args:
command: string, list or tuple, The command to run (e.g. ['gsutil', 'cp',
...])
timeout: number, Seconds to wait before timing out the command.
env: dict or None, Extra environmental variables use with this command.
Returns:
(stdout, stderr, returncode) returned from the command.
Raises:
error.SDKError: If the command cannot be run.
"""
# Add the passed in variables to the precomputed environment (without
# altering either dictionary).
if env:
env = dict(self._env, **env)
else:
env = self._env
p = subprocess.Popen(
_PrepareCommand(command), stdout=subprocess.PIPE,
stderr=subprocess.PIPE, cwd=os.path.dirname(self._sdk_dir), env=env)
if TIMEOUT_ENABLED:
out, err = p.communicate(timeout=timeout)
else:
if timeout:
sys.stderr.write(
'Warning: timeout specified, but subprocess32 is not available.')
out, err = p.communicate()
# TODO(magimaster): Change this to raise an error if returncode isn't 0
return out, err, p.returncode
driver.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录