【问题标题】:Run `sox` command line program with foreach?用foreach运行`sox`命令行程序?
【发布时间】:2018-07-08 07:27:39
【问题描述】:

我有一个 zip 文件,里面有很多目录和文件。某处是.vox 文件。

我在 PowerShell 中有解压缩并找到所有 .vox 文件的脚本。

我有命令行程序sox,它可以将vox文件转换为mp3。但它只在cmd中有效。

sox -t raw -r 8000 -e a-law inputfile outputfile

是否可以在带有inputfile 和outputfile 变量的PS 下运行此命令,这样我就可以将sox 与大量vox 文件一起使用?也许foreach?

【问题讨论】:

  • &"xxx\sox-14-4-2\sox.exe" "-t" "raw" "-r" "8000" "-e" "a-law" "$way .vox" "$way.mp3"
  • 如果你已经有一个脚本,最好包含它的代码,这样我们就可以看到你在做什么。如果您编辑您的问题以包含此内容,您将获得更相关的答案。

标签: powershell


【解决方案1】:

这样的东西应该可以工作

$sourceDirectory = "C:\voxfiles"
$destinationDirectory = "C:\soxfiles"

# Grab the list of files
$voxFiles = Get-ChildItem -Path $sourceDirectory -Filter "*.vox"

# Loop over the files
foreach ($voxFile in $voxFiles) {
    $inputFile = $voxFile.FullName
    $outputFile = Join-Path -Path $destinationDirectory -ChildPath $voxFile.Name

    # Call CMD
    & "Sox -t raw -r 8000 -e a-law $inputFile $outputFile"
}

Running CMD command in Powershell

【讨论】:

  • 不认为a-law $() $inputFile $outputFile 中的$() 实际上是必需的吗?
  • 很好发现@JamesC。 - 为了清晰起见,这是快速重构的残余!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-04
相关资源
最近更新 更多