Python Forum

Full Version: How to ignore - ERROR: The system was unable to find the specified registry key or va
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def isAlreadyInstalled(lookupRegistryKey):
    consoleLines = os.popen('reg query "' + APP_REGISTRY_KEY + "\\" + VERSION_SYSTEM_NAME + '"').readlines()
    if len(consoleLines) == 0:
        return False
    return True
I have this snippet. The problem is that it gives this error in the command line without stoping the execution ( wich is ok for my cas), I just want to ignore this error.

ERROR: The system was unable to find the specified registry key or value.
Does it also error in python?
No, my script is working ok. But this just pops there and i don't want to see it.

I'm looping for 5 minutes, call this method evrey second to check if a program is installed or not. I want to ignore this if possible somehow here inside the method
use try/except block, with the except capturing the specific error
and content of except 'pass'
  
 def isAlreadyInstalled(lookupRegistryKey):
        try:
            consoleLines = os.popen('reg query "' + APP_REGISTRY_KEY + "\\" + VERSION_SYSTEM_NAME + '"').readlines()
            if len(consoleLines) == 0:
                return False
            return True
        except OSError:
            pass
This is not working.
you haven't shown the error message.
Post that verbatim please
This is the error shown in the command line:

ERROR: The system was unable to find the specified registry key or value.
This error does not look like a python generated error traceback as it is incomplete.
if that's all you have, then you need to show more code, especially the 'lookupRegistryKey'
method or function (or package name if in a package). Soesn't loog like a winreg error either.

Can't help with information provided.
If it's not stopping the execution of the program, it's not an error from Python's perspective. A try/except block certainly won't work. I don't know if there is anything you can do in Python to stop it. Is there perhaps an option to the system command you are using that would suppress the error output?
APP_REGISTRY_KEY - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
lookupRegistryKey = theNameOfTheApplication

@ichabod801 - there is but in this case my condition( if len(consoleLines) == 0: ) will always be false since.