powershell - 使用 Powershell 打印包含制表符的 txt 文件
问题描述
解决方案
You're close, and you stumbled onto a workaround yourself - the use of Out-String
. You can add Out-String
to the pipeline before sending the content to the printer:
Get-Content $fname | Out-String | Out-Printer -Name "Microsoft XPS Document Writer"
If the above isn't working for you you can try processing the tab character yourself:
( Get-Content $fname -Raw ).Split( "`t" ) -Join "`t"
If that displays the output as you're expecting, you can pipe that to Out-Printer
(Out-String
isn't necessary because -Join
concatenates into a string):
( Get-Content $fname -Raw ).Split( "`t" ) -Join "`t" |
Out-Printer -Name "Microsoft XPS Document Writer"
However, this seems like it may be a bug with Out-Printer
, as comments and other answers have yielded varying success rates. The workarounds above are known to work on at least Windows 10.0.15063.0
(the version I'm currently running and tested with), but may have stopped working in later versions.
You may try converting the tabs to spaces as a workaround:
# This is set to 5 spaces here, but can be any number of
# spaces you want to represent a tab character
$replaceTabString = " "
( Get-Content $fname -Raw ).Replace( "`t", $replaceTabString ) |
Out-Printer -Name "Microsoft XPS Document Writer"
推荐阅读
- php - 当项目上传到服务器时,'password_hash() 期望参数 2 为整数,字符串给定'
- python - 保存/加载包装在 sklearn 兼容估计器中的 PyTorch 模型
- python-3.x - 使用 Python asyncio 运行并等待来自同步函数的异步函数
- php - 通过用户名或电子邮件进行身份验证失败并出现 DBAL 异常:未定义偏移量:1
- spring-batch - Spring Batch:我们如何从数据库中预加载值并将其用于处理器部分
- video - FFMPEG 视频合并。只有第一个视频显示
- pdf - PDF TJ 算子
- python - Scrapy 实际上在哪里执行 html 请求?
- reactjs - 在 React 上更新数组的状态
- typescript - 在 JestJS 中测试私有方法