Device Manager doesn't log files when ran in the background

I have a Arduino DUE and I’m trying to log the device monitor’s output inside a log file. When I run the command without it being a background operation it creates the logfiles as it should but when I run it as a background operation it doesn’t create any logfiles, here is the command I ran:

platormio device monitor --verbose --filter log2file &

It also hangs when I don’t run in as a background operation, I have a shell script where I read the log file after the platfomrio device monitor is called:

platformio device monitor --verbose --filter log2file
logfile=$(ls -t /logs/device-monitor* | head -1)

Or if possible is there any way to automate in a shell script to end the device monitor once the program is done ?

The reason why you can’t detach pio device monitor is that it is waiting for some input on stdin and the process becomes suspended.

One possible solution is to use gnu screen like that

screen -d -m -S DM platformio device monitor --filter log2file &

While running pio in the screen session, you are able to access the log file written by the pio device monitor as usual.

To stop it just type

screen -S DM -p 0 -X stuff "^C"

The phrase DM used in the two commands is arbitrary - you can choose another you like.

For more details please have a look at serverfault

P.S.: There is no --verbose option :wink:

platformio device monitor -h
Usage: platformio device monitor [OPTIONS]

  -p, --port TEXT              Port, a number or a device name
  -b, --baud INTEGER           Set baud/speed [default=9600]
  --parity [N|E|O|S|M]         Enable parity checking [default=N]
  --rtscts                     Enable RTS/CTS flow control
  --xonxoff                    Enable software flow control
  --rts INTEGER RANGE          Set initial RTS line state  [0<=x<=1]
  --dtr INTEGER RANGE          Set initial DTR line state  [0<=x<=1]
  --echo                       Enable local echo
  --encoding TEXT              Set the encoding for the serial port (e.g.
                               hexlify, Latin-1, UTF-8) [default=UTF-8]
  -f, --filter TEXT            Apply filters/text transformations
  --eol [CR|LF|CRLF]           End of line mode [default=CRLF]
  --raw                        Disable encodings/transformations of device
  --exit-char INTEGER          ASCII code of special character that is used to
                               exit the application [default=3 (Ctrl+C)]
                               [default: 3]
  --menu-char INTEGER          ASCII code of special character that is used to
                               control terminal (menu) [default=20 (DEC)]
  --quiet                      Diagnostics: suppress non-error messages
  --no-reconnect               Disable automatic reconnection if the
                               established connection fails
  -d, --project-dir DIRECTORY
  -e, --environment TEXT       Load configuration from `platformio.ini` and
                               the specified environment
  -h, --help                   Show this message and exit.

1 Like