find command with subprocess not working with out Shell=True

后端 未结 1 1265
一整个雨季
一整个雨季 2021-01-22 18:18

I have below lines in my code. I have embedded a short a line which fetches the list of files that are older than 10 mins. My sub process have been failing with few errors. It s

相关标签:
1条回答
  • 2021-01-22 18:56

    if it works with shell=True, and not without, that means that the pattern is expanded with shell=True.

    To emulate this behaviour just use glob.glob and compose your command argument list like this:

    cmd = ['find'] + glob.glob('/myapp/uat/aws/6.3/domains/*/appnodes/*/*/log/bwappnode.log') + ['-type','f','-mmin','+10']
    

    Which could be written very easily in pure python:

    import glob,os,time
    current = time.time()
    old_files = [x for x in glob.glob("/myapp/uat/aws/6.3/domains/*/appnodes/*/*/log/bwappnode.log") if current - os.path.getmtime(x) > 600]
    
    0 讨论(0)
提交回复
热议问题