可使用python交互是调用gemini cli与qwen code cli,输入命令后捕获输出
import subprocess
import threading
import time
# 启动 cmd 进程
process = subprocess.Popen(
['gemini'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
encoding='gbk', # Windows 控制台常用 gbk
bufsize=0
)
# 读取输出的线程
def read_output():
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print("输出:", output.strip())
# 开启输出监听线程
threading.Thread(target=read_output, daemon=True).start()
# 发送命令
def send_cmd(cmd):
process.stdin.write(cmd + '\n')
process.stdin.flush()
time.sleep(0.5) # 等待输出(实际项目可用更智能的同步机制)
send_cmd('写一个代码')
# 结束
process.stdin.write('exit\n')
process.stdin.flush()
process.wait() 网友回复
如何让ai帮我自动在小红书或抖音上自动根据需求截流与潜在客户聊天拉客?
如果用go编写一个在virtualbox中启动的简单操作系统?
go如何搭建一个零信任网络?
如何用python实现一个公网代理访问软件?
如何用go实现一个公网代理访问软件?
如何用python实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
如何用go实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
何为Shadowsocks 代理?
python如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?
nodejs如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?


