我从here中提取了Bash脚本,它使用ffmpeg和cygwin扩展来检查AVI文件是否存在坏帧。我能够在Mingw中执行代码。我把ffmpeg.exe(ren ffmpeg),cygwin1.dll&在Mingw的bin目录中的cygz.dll(/ c / mingw / bin /)。现在,我希望将此bash代码移植到PowerShell。任何人都可以在这个上发布一些PowerShell之光吗?
脚本: (路径:/ c / mygw / bin / AviConvert)
#!/bin/bash
FFMPEG="ffmpeg"
LIST=`find | grep \.avi$`
for i in $LIST; do
OUTP="$i.txt"
OUTP_OK="$i.txt.ok"
TMP_OUTP="$i.tmp"
if [ -f "$OUTP" -o -f "$OUTP_OK" ] ; then
echo Skipping "$i"
else
echo Checking "$i"...
RESULT="bad"
ffmpeg -v 5 -i "$i" -f null - 2> "$TMP_OUTP" && \
mv "$TMP_OUTP" "$OUTP" && \
RESULT=`grep -v "\(frame\)\|\(Press\)" "$OUTP" | grep "\["`
if [ -z "$RESULT" ] ; then
mv "$OUTP" "$OUTP_OK"
fi
fi
done
答案 0 :(得分:3)
如果您无法在PowerShell中找到已经熟化的类似内容,那么您唯一的机会就是了解此脚本的逻辑,并从头开始在PowerShell中编写一个,因为存在很大差异。
查看语法/命令的差异并进行适当的翻译。网络中提供的一些 Bash vs Powershell 相关帖子/文档,例如this。当然,请参阅PowerShell入门手册。例如, for 的语法不同,对于PowerShell,它的语法是:
for (_init_, _cond_, _incr_) {
_operators_
}
顺便说一句,在你的情况下,最好使用 foreach ,即有类似的内容:
(get-childitem $path -Recurse | select-string -pattern .avi | % {$_.Path} > matchingfiles.txt)
$FILESARRAY = get-content matchingfiles.txt
foreach ($FILE in $FILESARRAY)
{
(get-content $FILE ) |foreach-object {$_ -replace $find, $replace} | set-content $FILE
}