我正在使用subprocess.Popen在python中作为脚本的一部分进行调用和执行。 subprocess.Popen(command,stdin=subprocess.PIPE, stdout=subprocess.PIPE)
。可执行文件需要在大于80/24的子进程终端/窗口/空间中打开,否则结果将被截断。我需要将输入/标志调整为子流程,以便更改列数。我已经尝试过env= {'COLUMNS':'300'}
,但这无济于事。
我使用python 2.7
subprocess.Popen(command,stdin=subprocess.PIPE, stdout=subprocess.PIPE)
执行的命令并返回结果文本,如果您应该将此文本保存在变量中并进行解析,则可以使用以下命令:
import os
command = "some command"
res = os.popen(command).read() # get all content as text
res = list(os.popen(command)) # get lines as array elements
用于使用Python更改终端大小:
import os
rows = raw_input("rows: ")
cols = raw_input("cols: ")
os.system("resize -s {row} {col}".format(row=rows, col=cols))