Python 模拟后自动退出ngspice

Python 模拟后自动退出ngspice,python,os.system,pspice,Python,Os.system,Pspice,我正在从事一个自动化项目,该项目要求我在ngspice中启动一个模拟,在.txt文件中获取数据,然后退出ngspice。我有以下代码可以调用ngspice: import sys import os def invoke_ngspice(): os.system(r"C:\Users\MyPC\Desktop\GUI\ngspice\bin\ngspice_con.exe C:\Users\MyPC\Desktop\GUI\ngspice\bin\test_circuit.circ")

我正在从事一个自动化项目,该项目要求我在ngspice中启动一个模拟,在.txt文件中获取数据,然后退出ngspice。我有以下代码可以调用ngspice:

import sys
import os

def invoke_ngspice():
    os.system(r"C:\Users\MyPC\Desktop\GUI\ngspice\bin\ngspice_con.exe C:\Users\MyPC\Desktop\GUI\ngspice\bin\test_circuit.circ")
    os.system(r"quit")

虽然调用上述函数可以完美地完成模拟和保存部分,但我无法退出,因为ngspice保留执行。有没有干净地戒烟的方法?我不想每次都在ngspice命令窗口中手动键入quit或终止它,因为模拟时间是可变的

所以我找到了使用控制回路系统地退出ngspice的方法。在test_circuit.circ文件中,我在.control部分添加了quit语句,就这样

.control 
set filetype=ascii
run 
wrdata temp_file abs(v(A_1)-v(B_1)) 
quit
.endc