You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

3 weeks ago
import os
import subprocess
# 输出文件路径
output_file = r"d:\output.txt" # 可修改为您需要的路径
# 构建命令
command = r"D:\dsWork\dsProject\dsRag\mtef-go-3\mtef-go.exe -d D:\dsWork\dsProject\dsRag\static\Txt\化学方程式_CHEMISTRY_1.docx -o " + output_file
try:
# 执行命令并捕获输出指定编码为utf-8
result = subprocess.run(command, shell=True, check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
encoding='utf-8',
errors='ignore')
# 将输出写入文件处理None值情况
with open(output_file, "a", encoding='utf-8') as f:
if result.stdout:
f.write(result.stdout)
if result.stderr:
f.write(result.stderr)
print(f"命令执行成功,输出已保存到 {output_file}")
except subprocess.CalledProcessError as e:
print(f"命令执行失败: {e}")
with open(output_file, "a", encoding='utf-8') as f:
f.write(f"命令执行失败: {e}\n")
if e.stderr:
f.write(f"错误输出: {e.stderr}")