由于程序需要用java和python混用,所以可以取巧,就是在python中调用cmd,在cmd中执行java
所以,进行了一下测试。完美运行
import os
with open("text1.txt","w",encoding="utf8") as file1:
mystr = os.popen("ipconfig") # popen与system可以执行指令,popen可以接受返回对象
mystr = mystr.read() # 读取输出
file1.write(mystr) #写入文件