Run the given command in the shell returning whether the command succeeded. If 'error_msg' is set, log the error message on failure. If 'exit_on_error' is True, exit the program on failure. If 'out_file' is specified, log all output to that file.
(cmd, error_msg=None, exit_on_error=True, out_file=None)
| 126 | sys.exit(1) |
| 127 | |
| 128 | def exec_cmd(cmd, error_msg=None, exit_on_error=True, out_file=None): |
| 129 | """Run the given command in the shell returning whether the command |
| 130 | succeeded. If 'error_msg' is set, log the error message on failure. |
| 131 | If 'exit_on_error' is True, exit the program on failure. |
| 132 | If 'out_file' is specified, log all output to that file.""" |
| 133 | success = True |
| 134 | if out_file: |
| 135 | with open(out_file, 'w') as f: |
| 136 | ret_val = subprocess.call(cmd, shell=True, stderr=f, stdout=f) |
| 137 | else: |
| 138 | ret_val = subprocess.call(cmd, shell=True) |
| 139 | if ret_val != 0: |
| 140 | if error_msg: LOG.info(error_msg) |
| 141 | if exit_on_error: sys.exit(ret_val) |
| 142 | success = False |
| 143 | return success |
| 144 | |
| 145 | def exec_hive_query_from_file_beeline(file_name): |
| 146 | if not os.path.exists(file_name): |
no test coverage detected