0

How to catch os.system exceptions with Python? | ¿Cómo capturar excepciones de os.system con Python?

Hellooo friends! Who help me with how I could catch the exceptions even the outputs of os.system(). Suppose I have a console program that allows executing CMD codes, and the user is asked to enter the command to use, so if the user enters the command incorrectly, such as cld instead of cls, I want to catch the exception of that mistake. How would you do? I hope you help me :D Holaaaaa amigos! Quién me ayuda con saber cómo podría capturar las excepciones incluso las salidas de os.system(). Supongamos que tengo un programa de consola que permite ejecutar códigos del CMD, y se le pide al usuario que introduzca el comando a usar, entonces si el usuario ingresa el comando de forma incorrecta como por ejemplo cld en vez de cls quiero capturar la exception de ese error. ¿Cómo haría? Espero me ayuden :D

21st Mar 2022, 11:51 PM
Anthony Carrillo
Anthony Carrillo - avatar
4 Respuestas
0
FF9900 Thank you very much for replying, sorry for replying late XD By the way, what you told me works for me, but specifically it doesn't work for what I'm doing. Is it possible to catch the exception of a .exe code program? For example: I have a folder with adb.exe files I want to use Python to execute adb.exe commands and catch exceptions that occur if the entered command is invalid or something went wrong, suppose: try: subprocess.call(" adb.exe devices") print("Connected") except: print("Phone not connected) And the phone is not connected, I want the "Phone not connected" message to be printed. Can it be done? Thanks, any comments are welcome positive.
22nd Mar 2022, 7:14 PM
Anthony Carrillo
Anthony Carrillo - avatar
0
Thank you for information!
22nd Mar 2022, 8:09 PM
Anthony Carrillo
Anthony Carrillo - avatar