#!/usr/bin/env python3

""" Runs a command and then passes the output to Cinnamon via DBus asynchronously

Usage:  cinnamon-subprocess-wrapper ls ~/
"""

import subprocess
import sys
import dbus

if __name__ == "__main__":
    process_id = int(sys.argv[1])
    result = subprocess.check_output(sys.argv[2:])
    session_bus = dbus.SessionBus()
    dbus = session_bus.get_object("org.Cinnamon", "/org/Cinnamon")
    PushSubprocessResult = dbus.get_dbus_method('PushSubprocessResult', 'org.Cinnamon')
    PushSubprocessResult(process_id, result)
