gpt4 book ai didi

python - 在 cli 函数中使用 python 的子进程会破坏命令行

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:21:12 25 4
gpt4 key购买 nike

我编写了一个 python 脚本来批处理视频文件,并为其创建了一个 CLI 绑定(bind)。您可以找到存储库 here .

作为脚本的一部分(因为视频处理是计算密集型的)我是 using Python's subprocess module to achieve some parallelization .

我从命令行调用我的脚本:

repositorg vidproc -p "-crf 16 -c:a copy -filter:v 'crop=1080:1080:420:0'" nd750_a00{80..86}.MOV

而且效果很好。但是,执行后,它破坏了我的终端。我再也看不到我在输入什么,但它仍然被发送到终端。这是我多次终止当前行,然后键入 ls 并按回车键的示例:

chymera@zenbookhost ~/data/cameras/nd750/a $ ^C
chymera@zenbookhost ~/data/cameras/nd750/a $ ^C
chymera@zenbookhost ~/data/cameras/nd750/a $ ^C
chymera@zenbookhost ~/data/cameras/nd750/a $ ^C
chymera@zenbookhost ~/data/cameras/nd750/a $ nd750_a0000.mkv nd750_a0016.mkv nd750_a0032.mkv nd750_a0048.mkv nd750_a0064.mkv nd750_a0079.MOV
nd750_a0001.mkv nd750_a0017.mkv nd750_a0033.mkv nd750_a0049.mkv nd750_a0065.mkv nd750_a0080.mkv
nd750_a0002.mkv nd750_a0018.mkv nd750_a0034.mkv nd750_a0050.mkv nd750_a0066.mkv nd750_a0080.MOV
nd750_a0003.mkv nd750_a0019.mkv nd750_a0035.mkv nd750_a0051.mkv nd750_a0067.mkv nd750_a0081.mkv
nd750_a0004.mkv nd750_a0020.mkv nd750_a0036.mkv nd750_a0052.mkv nd750_a0068.mkv nd750_a0081.MOV
nd750_a0005.mkv nd750_a0021.mkv nd750_a0037.mkv nd750_a0053.mkv nd750_a0069.mkv nd750_a0082.mkv
nd750_a0006.mkv nd750_a0022.mkv nd750_a0038.mkv nd750_a0054.mkv nd750_a0070.mkv nd750_a0082.MOV
nd750_a0007.mkv nd750_a0023.mkv nd750_a0039.mkv nd750_a0055.mkv nd750_a0071.mkv nd750_a0083.mkv
nd750_a0008.mkv nd750_a0024.mkv nd750_a0040.mkv nd750_a0056.mkv nd750_a0072.mkv nd750_a0083.MOV
nd750_a0009.mkv nd750_a0025.mkv nd750_a0041.mkv nd750_a0057.mkv nd750_a0073.mkv nd750_a0084.mkv
nd750_a0010.mkv nd750_a0026.mkv nd750_a0042.mkv nd750_a0058.mkv nd750_a0074.mkv nd750_a0084.MOV
nd750_a0011.mkv nd750_a0027.mkv nd750_a0043.mkv nd750_a0059.mkv nd750_a0075.mkv nd750_a0085.mkv
nd750_a0012.mkv nd750_a0028.mkv nd750_a0044.mkv nd750_a0060.mkv nd750_a0076.mkv nd750_a0085.MOV
nd750_a0013.mkv nd750_a0029.mkv nd750_a0045.mkv nd750_a0061.mkv nd750_a0077.mkv nd750_a0086.mkv
nd750_a0014.mkv nd750_a0030.mkv nd750_a0046.mkv nd750_a0062.mkv nd750_a0078.mkv nd750_a0086.MOV
nd750_a0015.mkv nd750_a0031.mkv nd750_a0047.mkv nd750_a0063.mkv nd750_a0079.mkv

如您所见,ls 没有被打印出来,但它的输出是,尽管从提示符开始...

我在想:

  • 这是怎么回事?
  • 一旦发生这种情况,我该如何修复我的终端?
  • 如何防止我的脚本破坏终端?

最佳答案

一些进程可能关闭了echo。这可以使用 stty 命令进行检查。通常情况是这样的:

$ stty
speed 38400 baud; line = 0;
-brkint ixoff -imaxbel iutf8

如果它被关闭:

$ stty -echo

然后回车4次,输入stty:

$ $ $ $ $ speed 38400 baud; line = 0;
-brkint ixoff -imaxbel iutf8
-echo

要重新打开它,只需调用 stty echo

关于python - 在 cli 函数中使用 python 的子进程会破坏命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42683421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com