Skip to content

Commit db7ca6b

Browse files
committed
keep loging
1 parent 03ca198 commit db7ca6b

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

bolt/util.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,36 @@ def get_project_root():
2222
return project_root
2323

2424
def execute_command(command, log_file_path=None):
25-
logger.info("Executing command: %s", command)
26-
# Open the process with stderr merged to stdout
25+
logger.info("Executing command: %s", command.strip())
26+
27+
# Open the log file if provided
28+
log_file = log_file_path.open('a', encoding='utf-8') if log_file_path else None
29+
30+
# Launch process with combined stdout and stderr streams, and line buffering enabled.
2731
process = subprocess.Popen(
2832
command,
2933
shell=True,
3034
executable='/bin/bash',
3135
stdout=subprocess.PIPE,
3236
stderr=subprocess.STDOUT,
3337
text=True,
34-
bufsize=1 # Line-buffered output
38+
encoding='utf-8',
39+
bufsize=1 # line buffered
3540
)
36-
37-
# Capture output in real time
41+
42+
# Iterate over each line as it becomes available
3843
with process.stdout:
3944
for line in iter(process.stdout.readline, ''):
40-
logger.info(line.strip())
41-
if log_file_path:
42-
with open(log_file_path, 'a', encoding='utf-8') as log_file:
45+
if line:
46+
logger.info(line.strip())
47+
if log_file:
4348
log_file.write(line)
44-
process.wait()
49+
log_file.flush() # flush immediately for real-time logging
50+
process.wait() # wait for the process to complete
51+
52+
if log_file:
53+
log_file.close()
54+
4555
return process
4656

4757
def command_prepare(command):

0 commit comments

Comments
 (0)