useful-scripts icon indicating copy to clipboard operation
useful-scripts copied to clipboard

uq: cannot save result to file | uq: 无法保存输出

Open Vinfall opened this issue 1 year ago • 1 comments

今天用 uq 删除 Windows PowerShell 历史记录中的重复行时遇到 uq 输出不能保存的问题(可以正常输出到 stdout)。

我尝试过的命令:

# 脚本中记录的用法
uq ConsoleHost_history.txt 1.txt
# pipe
cat ConsoleHost_history.txt | uq > 1.txt
# redirect
uq ConsoleHost_history.txt > 1.txt

可能的原因:编码问题,ConsoleHost_history.txt 使用的也是 UTF-8,EOL是CR LF

我使用 dos2unix 转换的时候报错,手动移除对应字符后正常转换。但是 uq 的输出还是不能保存,所以和编码估计没关系。

$ dos2unix 1.txt
dos2unix: Binary symbol 0x06 found at line 3700
dos2unix: Skipping binary file 1.txt

临时解决方案:使用 script 捕捉 uq 的输出,不知道为什么这个可以正常工作……

script output.txt
uq 1.txt
exit

运行完之后手动移除 output.txt 文件头尾的 script header 即可。

Vinfall avatar Apr 20 '24 06:04 Vinfall

你好: 你的邮件我会尽快看的啦!!!

lkun avatar Apr 20 '24 06:04 lkun