【问题标题】:Grab output of a command lines in linux bash unusual result在 linux bash 异常结果中获取命令行的输出
【发布时间】:2013-11-21 17:06:17
【问题描述】:
#!/bin/bash
output=$(compare -subimage-search -metric mae large_image.png item.png result.png)
echo "Output is: $output"

显示如下:

7216.53 (0.110117) @ 6,4
Output is:

但我期待这样的事情

Output is: 7216.53 (0.110117) @ 6,4

在我看来,compare(imagemagick) 正在使用除 'print' 或 'echo' 以外的其他打印行命令

我对其他命令行没有问题,例如:

output=$(date)
echo "output is: $output"

这将产生:

output is: Fri Nov 22 01:02:07 PHT 2013

【问题讨论】:

  • 听起来您的比较命令没有写入 STOUT。如果你运行compare ... > /dev/null,你会看到任何输出吗?

标签: linux bash shell imagemagick compare


【解决方案1】:

可能compare 正在写信给stderr 而不是stdout

试试这个命令:

output=$(compare -subimage-search -metric mae large_image.png item.png result.png 2>&1)
echo "Output is: $output"

【讨论】:

  • 哇,谢谢,完美。我一直看到 2>&1 的例子,但直到现在才知道这一切是怎么回事。 tnx
猜你喜欢
  • 2020-01-06
  • 2014-09-26
  • 1970-01-01
  • 2013-01-01
  • 2014-06-15
  • 1970-01-01
  • 2016-04-30
  • 1970-01-01
相关资源
最近更新 更多