def main()

in cortado/rtas/at_command.py [0:0]


def main():
    target_host = _common.get_host_ip()
    host_str = "\\\\%s" % target_host

    # Current time at \\localhost is 11/16/2017 11:25:50 AM
    _, output, _ = _common.execute_command(["net", "time", host_str])

    if not output:
        raise _common.ExecutionError("Can't get time from the host")

    output_str = output.decode("utf-8")
    match = re.search(r"Current time at .*? is (\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+) (AM|PM)", output_str)
    if not match:
        raise _common.ExecutionError("No matches found in `net time` output")

    groups = match.groups()
    m, d, y, hh, mm, ss, period = groups
    now = datetime.datetime(
        month=int(m),
        day=int(d),
        year=int(y),
        hour=int(hh),
        minute=int(mm),
        second=int(ss),
    )
    if period == "PM" and hh != "12":
        now += datetime.timedelta(hours=12)

    # Add one hour
    task_time = now + datetime.timedelta(hours=1)

    # Round down minutes
    time_string = "%d:%d" % (task_time.hour, task_time.minute)

    # Enumerate all remote tasks
    _ = _common.execute_command(["at.exe", host_str])

    # Create a job 1 hour into the future
    retcode, output, stderr = _common.execute_command(["at", host_str, time_string, "cmd /c echo hello world"])

    if not output:
        raise _common.ExecutionError("No output from `at` command")

    output_str = output.decode("utf-8")

    if retcode == 1 and "deprecated" in output_str:
        log.error(f"Error while running `at`, not supported in this version of Windows: {output_str}")
        raise _common.ExecutionError("Error while running `at`")

    if retcode != 0:
        log.error(f"Error while running `at`: {stderr}")
        raise _common.ExecutionError("Error while running `at`")

    match = re.search(r"ID = (\d+)", output_str)
    if not match:
        raise _common.ExecutionError("No matches in `at` output")

    job_id = match.group(1)

    # Check status and delete
    _ = _common.execute_command(["at.exe", host_str, job_id])
    _ = _common.execute_command(["at.exe", host_str, job_id, "/delete"])