I’m trying to to a ls -l from python, to check for the last modification date of a file.
os.listdir doesn’t show the long list format.
subprocess.call shows the format, but actually prints it, and returns 0. I want to be able to put it in a variable. Any ideas ?
Also, I tried
subprocess.call("ls","*.py")
which answers
ls: cannot access *.py: No such file or directory
it works with shell=True, but if someone could explain why it doesn’t work without it, I’ll appreciate. If you know how to make it work, even better.
It doesn’t work without
shell=Truebecause the*is a shell expansion character – going from*.pyto a list of files ending in.pyis a function performed by the shell itself, notlsorpython.If you want to get the output of a command invoked via
subprocess, you should usesubprocess.check_output()orsubprocess.Popen.