import os import subprocess def run_command_from_txt(): # Find the .txt file in the current directory txt_files = [f for f in os.listdir('.') if f.endswith('.txt')] if not txt_files: print("No .txt file found in current directory.") return if len(txt_files) > 1: print("More than one .txt file found. Expected only one.") return txt_file = txt_files[0] # Read the command with open(txt_file, 'r', encoding='utf-8') as file: command = file.read().strip() if not command: print("The .txt file is empty.") return print(f"Running PowerShell command from {txt_file}:") print(command) # Run the command in PowerShell try: subprocess.run(["powershell", "-Command", command], check=True) except subprocess.CalledProcessError as e: print(f"Error running command: {e}") if __name__ == "__main__": run_command_from_txt()