【问题标题】:How can I run this command in a shell script如何在 shell 脚本中运行此命令
【发布时间】:2011-01-21 13:31:00
【问题描述】:

这是我的 shell 脚本,但它给出了错误:

#!/bin/sh

while getopts "i:o:" flag
do
   case $flag in
   i) file_input=$OPTARG
   ;;
   o) file_output=$OPTARG
   ;;
   esac
done

mplayer -nosound -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m \
              --crf 20 --threads auto --output $file_output - ) $file_input

错误信息是:

无法获取要写入的内存或文件句柄 ">(x264 --demuxer y4m --crf 20 --threads auto --output video.264 - )"!致命:无法初始化视频驱动程序。

当我在 putty 上运行这个 cmd 时:

mplayer -nosound -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m \
              --crf 20 --threads auto --output video.264 - ) video.wmv

效果很好..

我做错了什么?

【问题讨论】:

  • 所有解决方案都不是功能性的..

标签: linux shell x264 mplayer


【解决方案1】:

您使用的命令使用复杂的 bash 的 pipe stream to subshell 语法,即 >() 来实现您想要的。可能您的 /bin/sh(您在 shebang 中作为该脚本的 shell 调用)与您以交互方式使用的 shell(即 bash)不同?

【讨论】:

  • /bin/sh 可能是到 /bin/bash 的链接,但是在名称 /bin/sh 下,并非 bash 的所有功能都可用 - 特别是 '=>' 符号不支持。
  • @Jonathan:没有=> 符号。 = 是 mplayer 命令的一部分。 >(...) 是 Bash 解析的内容。
  • 并非总是如此。现在 Ubuntu 和 Debian 很流行,/bin/sh 通常在那里用 dash 实现,这是一个非常简约的严格 POSIX 兼容的 shell。
  • @thkala:你可能是对的 - 问题始于 = 和 > 之间,/bin/sh 不喜欢它,而 /bin/bash 喜欢。所以它又是“过程替换”......有道理。
【解决方案2】:

>(...) 进程替换运算符是特定于 Bash 的。如果 Bash 被称为 /bin/sh,它也不可用,因为在这种情况下,Bash 将自己限制在其功能的更合规的子集上。

只需在脚本开头使用#!/bin/bash 而不是#!/bin/sh

【讨论】:

    【解决方案3】:

    我建议你添加一些' 来保护你的特殊字符:

    mplayer -nosound -benchmark -vo 'yuv4mpeg:file=>(x264 --demuxer y4m --crf 20 --threads auto --output $file_output - )' $file_input
    

    【讨论】:

      猜你喜欢
      • 2019-09-02
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 2019-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多