2 # Copyright (c) 2016 Samsung Electronics Co., Ltd
4 # Licensed under the Flora License, Version 1.1 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://floralicense.org/license/
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
23 from tic.utils.error import TICError
25 def run(cmdln, catch=3):
26 logger = logging.getLogger(__name__)
27 if isinstance(cmdln, list):
32 cmd = shlex.split(cmdln)[0]
38 dev_null = os.open("/dev/null", os.O_WRONLY)
46 # both STDOUT and STDERR
47 sout = subprocess.PIPE
48 serr = subprocess.STDOUT
51 logger.info('subprocess open: %s', cmd)
52 p = subprocess.Popen(cmdln,
57 (sout, serr) = p.communicate()
58 out = ''.join(filter(None, [sout, serr]))
61 # No such file or directory
62 raise TICError('Cannot run command: %s' % cmd)
69 return (p.returncode, out)