def execute_program(console, prompt, program, timeout):
    """Execute a program remotely via a shell connection.

    :param console: console object
    :type console: :py:class:`pexpect:pexpect.spawn` - like class
    :param prompt: shell prompt
    :type prompt: str
    :param program: name of program to run
    :type program: str
    :param timeout: timeout for program execution in seconds
    :type timeout: int
    :return: program exit code
    :rtype: int
    """
    console.expect_exact(prompt)
    console.sendline(program + ' \\')
    console.expect_exact('\n')
    command_part_2 = '; echo Exit code: $?.'
    console.sendline(command_part_2)
    console.expect_exact(command_part_2)
    console.expect_exact('\n')
    console.expect('Exit code: (\\d+).', timeout=timeout)
    exit_code_bytes = console.match.group(1)
    console.expect_exact('\n')
    return int(exit_code_bytes.decode())
