|
7 | 7 | from pathlib import Path |
8 | 8 | # from zip import zip_files_and_folders |
9 | 9 |
|
| 10 | +def run_command_with_input(cmd): |
| 11 | + """执行命令并自动响应[Yes]/No提示""" |
| 12 | + process = subprocess.Popen( |
| 13 | + cmd, |
| 14 | + stdout=subprocess.PIPE, |
| 15 | + stderr=subprocess.STDOUT, # 合并标准错误到标准输出 |
| 16 | + stdin=subprocess.PIPE, |
| 17 | + text=True, # 启用文本模式 |
| 18 | + encoding='utf-8', # 设置编码 |
| 19 | + bufsize=1 # 行缓冲 |
| 20 | + ) |
| 21 | + |
| 22 | + # 实时读取输出并检测提示 |
| 23 | + output_lines = [] |
| 24 | + while True: |
| 25 | + line = process.stdout.readline() |
| 26 | + if not line: # 无输出表示进程结束 |
| 27 | + break |
| 28 | + |
| 29 | + print(line, end='') # 实时打印输出 |
| 30 | + output_lines.append(line) |
| 31 | + |
| 32 | + # 检测到[Yes]/No提示时自动输入yes |
| 33 | + if "Yes" in line: |
| 34 | + process.stdin.write("yes\n") |
| 35 | + process.stdin.flush() |
| 36 | + |
| 37 | + # 等待进程结束并获取返回码 |
| 38 | + returncode = process.wait() |
| 39 | + return subprocess.CompletedProcess(cmd, returncode, stdout=''.join(output_lines)) |
| 40 | + |
10 | 41 | def main(): |
11 | 42 | print("="*50) |
12 | 43 | print("="*50) |
@@ -62,14 +93,6 @@ def main(): |
62 | 93 | arrch = "x64" |
63 | 94 | output_name = output_name_template.replace('{{name}}', name).replace('{{version}}', version).replace('{{arch}}', arrch).replace('{{os}}', Machine) |
64 | 95 |
|
65 | | - # 检查操作系统和架构 |
66 | | - # if Machine not in task.get('os', []): |
67 | | - # print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前操作系统 {Machine}") |
68 | | - # continue |
69 | | - # if arrch not in task.get('arch', []): |
70 | | - # print(f"警告: 任务 [{i}/{len(config)} {task['name']}] 不支持当前架构 {arrch}") |
71 | | - # continue |
72 | | - |
73 | 96 | # 检查Python文件是否存在 |
74 | 97 | if not python_file.exists(): |
75 | 98 | print(f"错误: Python文件不存在 {python_file}") |
@@ -108,7 +131,8 @@ def main(): |
108 | 131 |
|
109 | 132 | # 打印并执行命令 |
110 | 133 | print("执行命令:", ' '.join(cmd)) |
111 | | - result = subprocess.run(cmd) |
| 134 | + # 使用增强的命令执行函数 |
| 135 | + result = run_command_with_input(cmd) |
112 | 136 |
|
113 | 137 | if result.returncode == 0: |
114 | 138 | print(f"(onefile)打包成功: {dist_path / output_name}") |
|
0 commit comments