I wanted to document my solution, which diverges slightly from the original intent but accomplished the purpose using a related method. I used the --cmd flag in a .bat file that was called by python to start mavproxy and that allowed me to send command through the --cmd flag. This only allowed commands to be sent upon startup, so after the commands were sent initially no more could be called using this method.
I wanted to download logs on a Companion Computer connected to a Flight Controller.
So I created a script that starts the mavproxy on the CC. The contents of the script are:
#!/bin/bash
mavproxy.py
Then I created a python script that would open the mavproxy process and send the required commands. The contents of the python script include:
import subprocess
import time
command_to_send = "log list\n" # MAVProxy command to list the available logs (running this is important before you use any other log module command)
mavproxy_process = subprocess.Popen(["mavproxy.py", "--console"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
# Send the command to mavproxy
try:
# Send the command to mavproxy
mavproxy_process.stdin.write(command_to_send)
mavproxy_process.stdin.flush()
time.sleep(15)
print("Command sent")
command_to_send = "log download 300\n" # MAVProxy command to download the log number 300
mavproxy_process.stdin.write(command_to_send)
mavproxy_process.stdin.flush()
#xtime.sleep(60)
print("Command sent")
# Read the response
response = mavproxy_process.stdout.read()
print(response)
finally:
# Close the process and cleanup
mavproxy_process.stdin.close()
mavproxy_process.stdout.close()
mavproxy_process.stderr.close()
mavproxy_process.terminate() # Terminate the process
Now just I have to figure out how to get a feedback once the log has been completely downloaded and kill the script.