admin管理员组

文章数量:1125549

We want to capture all output of console on an embedded board which running Linux.

cat /proc/cmdline | grep -oE 'console=\S+' shown console=ttyS2,115200n8

We would use a PC to login a testing board by tty terminal, such as minicom -D /dev/ttyUSB2, and then run a record command, and then disconnect tty, and then goto another board. Once test finished, we can check each recorded file which saved in each board.

I tested running cat /dev/ttyS2 | tee ttyS2.log or cat /dev/console | tee console.log in ssh session, they cannot capture messages outputted to console.

I also tested script command. It cannot capture following output too if run it in background.

#include <iostream>
#include <thread>

using namespace std;

// clang++ -std=c++23 -stdlib=libc++ bgrun.cpp 
int main(int argc, char *argv[])
{
    int timeout = argc > 1 ? stoi(argv[1]) : 1;

    while (true)
    {
        system("echo; date");
        cout << "cout: Waiting for " << timeout << " second(s)" << endl;
        cerr << "cerr: Waiting for " << timeout << " second(s)" << endl;
        this_thread::sleep_for(chrono::seconds(timeout));
    }

    return 0;
}

本文标签: