[BangPypers] Capture and save running process on Python 3.6

Ajinkya Bobade ajinkyabobade93 at gmail.com
Wed Nov 1 18:11:32 EDT 2017


Hello,

Hope someone can help me on this. In the following code, I want to capture
print('Recording GPS Position...')  on sd card, for now, this is printing
on terminal directly I want to capture this runtime process (p_1) from
terminal and store on sd card as it is being executed how do I do this.
Also in general what is a way to capture and store processes in runtime
from terminal and store on 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()


More information about the BangPypers mailing list