[LABI] tema02: added cmd_comand.py to run command "ls -la" + sys.argv[1]
This commit is contained in:
parent
c49a773e0e
commit
b3cc717e39
|
@ -0,0 +1,18 @@
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print("Usage: python Ex3.py <directory_path> <ignore_term>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
directory_path = sys.argv[1]
|
||||||
|
ignore_term = sys.argv[2]
|
||||||
|
|
||||||
|
try:
|
||||||
|
output = subprocess.check_output(["ls", "-la", directory_path], universal_newlines=True)
|
||||||
|
lines = output.split("\n")
|
||||||
|
filtered_lines = [line for line in lines if ignore_term not in line]
|
||||||
|
print("\n".join(filtered_lines))
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
print("Error: could not list directory.")
|
||||||
|
sys.exit(1)
|
Loading…
Reference in New Issue