编写批处理脚本的最佳方法是什么?

时间:2011-03-30 07:24:38

标签: python ant batch-file makefile batch-processing

我有大约20个脚本,每个脚本产生一个输出文件作为输出,作为输入反馈给下一个文件。我现在想为用户提供从脚本中的任何位置重启批处理脚本的选项。

我的朋友建议使用make或ant,为每个python脚本定义目标。我想知道你的(高级黑客)建议。

谢谢

1 个答案:

答案 0 :(得分:2)

做这样的工作:

Target: dependencies
  commands

根据您的脚本,您可以尝试这种类型的Makefile:

Step20: output19
  script20   #reads output19 and produces final output

Step19: output18
  script19   # reads output18 and produces output19

.. etc ..

Step2: output1
  script2   # reads output1 and produces output2

Step1:
  script1   # produces output1

这样,在生成上一步的输出之前,每个脚本都不会运行。运行 make Step20 将沿着整个链向下移动,如果没有输出,则从script1开始。或者,如果output15存在,它将开始运行script16。