循环调用过程,需要很长的时间才能完成。我该如何打破它呢? [英] Loop calls process that takes a long time to complete. How do I break out of it?

查看:184
本文介绍了循环调用过程,需要很长的时间才能完成。我该如何打破它呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我到这个解决方案与从这里(它找到一个目录列表与HandBrakeCLI处理,并把结果在硬codeD目录)帮助:

I got to this solution yesterday with help from here (it's finding a list of directories to process with HandBrakeCLI, and putting the results in a hard-coded directory):

#!/bin/bash
source_dir=/Volumes/VolumeName
dest_dir=/Volumes/OtherName

export dest_dir # export allows use by subprocesses!

find "$source_dir" -type d -name "VIDEO_TS" -exec bash -c '
  for dir; do
    name=${dir%/VIDEO_TS}
    name=${name##*/}
    ./HandBrakeCLI -i "$dir" -o "$dest_dir/$name.m4v"
  done
' _ {} +

这个shell脚本工作正常,但如果我尝试通过杀死的主要进程停止它:

The shell script works fine, but if I try to stop it by killing the main process:

kill -9 <pid>

这似乎工作,但然后回来生活,并与被发现生成的列表的下一个文件调用HandBrakeCLI。

it seems to work but then comes back to life and calls HandBrakeCLI with the next file in the list generated by find.

有可靠停止整个事情的方法吗?我假设,不知怎的到CLI未来的呼叫被排队/缓存,但也有人解释发生了什么吗?

Is there a way of reliably stopping the whole thing? I'm assuming that somehow the future calls to the CLI are being queued/cached, but could someone explain what's happening please?

推荐答案

您的脚本是由从发现调用的bash不必要的复杂。我建议遍历查找的输出。

Your script is made unnecessarily complex by invoking bash from find. I suggest iterating over the output of find.

#!/usr/bin/env bash

source_dir=/Volumes/VolumeName
dest_dir=/Volumes/OtherName

find "${source_dir}" -type d -name "VIDEO_TS" | while read dir; do
  name=${dir%/VIDEO_TS}
  name=${name##*/}
  ./HandBrakeCLI -i "${dir}" -o "${dest_dir}/${name}.m4v"
done

这篇关于循环调用过程,需要很长的时间才能完成。我该如何打破它呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆