linux上程序执行的自动化



为了在课堂作业中分析某些结果,我必须进行几个实验。对于每个结果,我必须通过改变终端的参数来运行一行代码。我想知道是否有一种方法可以自动执行此操作,从而节省我每次运行程序和更改值的麻烦。附件是我每次必须执行的代码行:

teaa/examples/scripts/run-python.sh teaa/examples/python/rf_mnist.py 
         --numTrees 10 --maxDepth 7 --pcaComponents 40

我希望这些代码行自动执行n次,并且在每次执行中,参数'numTrees, maxDepth和pcaccomponents '在一组值范围内更改。

我还没有真正尝试过任何解决方案。我从来没有在终端编程过,我不知道从哪里开始。

对于更复杂的进程操作,应该使用stdlib Python中的subprocess模块…但是如果您只想一次性运行此命令行,则可以使用普通的旧os.system函数—如下代码:

import os
for nt in range(1,21):                                                                                                                                                                                                                                        
    for md in range(1,11):
        for pc in range(20,100,10):
            os.system(f'teaa/examples/scripts/run-python.sh teaa/examples/python/rf_mnist.py  --numTrees {nt} --maxDepth {md} --pcaComponents {pc}')

将运行您的程序为numTrees = 1,2…20, maxDepth = 1,…10和pcaccomponents = 20,…90

最新更新