2015-03-02 47 views
1

我正在扫描文件夹中的音频文件并将它们转换为mp3。 在RUBY很有效。 但是,一旦第一次转码完成,它会停止整个循环。下面是我的代码过程的细分。在红宝石循环中运行几个'exec'

def scanFolder 
    # lots of code above to get folder list, check for incorrect files etc.. 
    audioFileList.each { 
    |getFile| 

    exec_command = "ffmpeg #{getFile} #{newFileName}" 
    exec exec_command 
    } 
end 

发生什么事情是,它转码它找到的第一个文件,然后停止整个功能。有没有办法强制它继续?

ffmpeg的不运行,并在瞬间准确地完成,所以它不是什么破

回答

4

exec代替运行给定命令当前进程。例如:

2.0.0-p598 :001 > exec 'echo "hello"' 
hello 
[email protected]:$ 

你可以看到如何exec替换系统echo的IRB然后自动退出。

因此请尝试使用system代替。这里使用system相同的例子:

2.0.0-p598 :003 > system 'echo "hello"' 
hello 
=> true 
2.0.0-p598 :004 > 

你可以看到执行命令后我仍然在IRB及其未退出。

这使得您的代码如下:

def scanFolder 
    # lots of code above to get folder list, check for incorrect files etc.. 
    audioFileList.each { 
    |getFile| 

    exec_command = "ffmpeg #{getFile} #{newFileName}" 
    system exec_command 
    } 
end