0

I want to capture "print('Recording GPS Position...')" on the SD card. For now, this is printing on terminal directly I want to capture this runtime process (p_1) from terminal and store on the SD card as it is being executed. How do I do this?

Also in general what is a way to capture and store processes at runtime from terminal and store on the SD card (note I do want to store processes as it is being executed and not after its execution is done).

import sys
import os
import time
import subprocess, shlex
import signal
import serial
import psutil
from subprocess import Popen, PIPE

def recording():
    flag = 0
    ser = serial.Serial('/dev/ttyACM0', 921600, timeout=1)
    ser.flushOutput()

    # ROSBAG Recordings (Shell commands that execute the messages on the terminal)

    messages = 'rosbag record -o GPS_Position.bag dji_sdk/gps_position', 'rosbag record -o IMU_Data.bag dji_sdk/imu', 'rosbag record -o Attitude.bag dji_sdk/attitude', 'rosbag record -o Velodyne_Packets.bag velodyne_packets', 'rosbag record -o Velodyne_Points.bag velodyne_points',  # rosbag record -o Velocity.bag dji_sdk/velocity'

    while flag == 0:
        try:
            args1 = shlex.split(messages[0])  # messages[0] = rosbag record -o GPS_Position.bag dji_sdk/gps_position
            #print (args1)
            p_1 = subprocess.Popen(args1, stdout=PIPE)
            print('Recording GPS Position...')
            p_1.stdout.flush()
CDspace
  • 2,639
  • 18
  • 30
  • 36
Ajinkya
  • 1,797
  • 3
  • 24
  • 54

1 Answers1

1

You'll want to choose a directory for your SD card, and instead of print()ing to the terminal you'll write() to the file you choose.

Here is the documentation: https://docs.python.org/3/tutorial/inputoutput.html

Edit: it's been answered better here https://stackoverflow.com/a/8024254/8240691 but it would still be worth your while to look over the input/output documentation.

Luke McPuke
  • 354
  • 1
  • 2
  • 12
  • Thank you I could get it working for text format please see here:https://stackoverflow.com/questions/47079458/redirecting-ros-bag-file-to-external-storage-using-python. I am trying to change from txt format to bag format – Ajinkya Nov 02 '17 at 18:28