0

Is there anyway to access a Raspberry PI remotely but rather viewing the desktop, it brings up the CLI interface which has a program running to be able to test and fix any issues that may arise within the software itself? The program runs in command-line mode so when i remote in I cant actually view the program that would be visible on the actual machine, but rather the desktop. Any suggestions? thank you

1
  • Why not write to a log file?
    – CoderMike
    Nov 1, 2021 at 11:28

1 Answer 1

2

access a Raspberry PI remotely but rather viewing the desktop, it brings up the CLI interface

Yes, that's what ssh is for; actually it allows for either logging into the GUI desktop or just a CLI shell.

which has a program running to be able to test and fix any issues that may arise within the software itself

There's nothing to generically "test and fix any issues that may arise" since some programs are very different from others. I think what you mean, though, is you want to be able to run a long running process that outputs errors etc. on the command line, and you want to be able to log in remotely and observe this similar to the way you might observe it in a terminal emulator on the desktop.

What you want is screen or tmux. Both of these have been around for a long time (longer than the pi), and are in widespread use in the linux world, and you will find many many tutorials, how-tos, etc. online about them (including on our old blog, but ignore the recommendation about installing from source there, just use sudo apt install tmux). A quick introduction:

  • Start a new tmux session: tmux new-session -s whatever (whatever can be anything, it is just a label so you can reconnect later). A bar will appear along the bottom of the screen indicating you are now in a tmux session, which starts off by running a CLI shell (so everything else probably looks the same). You can do anything you normally do on the commandline, including start whatever software you want.
  • Detach from the session: Ctrlb then d. You return to where you were before you started the session, and everything in the session will have disappeared. Notice this is not a CLI command, it's a key combo, which means you can do it with software running in the foreground. That software will continue running although you cannot see it.
  • Reattach: tmux attach-session -t whatever The stuff in the session will reappear. If you left software running in the foreground, it still will be unless it has stopped in the meantime.

Once started tmux sessions last until they are terminated -- you can log in and out of the machine locally or remotely etc., and you can actually attach to a session from multiple places at once.

8
  • hi thank you for this - sorry if I wasn't very clear. Basically what we need to do is login remotely and view what is running on the screen which would be a program running in CLI mode and we want to be able to control the program with a mouse and keyboard to be able to test it if we encounter issues.
    – inni
    Nov 2, 2021 at 0:49
  • The part about being "able to control the program with a mouse and keyboard to be able to test it" is something you have to do yourself, or via a means appropriate to whatever program it is. There is no such thing as a universal control/test harness for absolutely any and all software. However, if your program already has those features when you run it in CLI mode already, then: 1) It will run exactly the same way in a tmux or screen session, which has a command line exactly like your normal one (because it just nests your normal shell)...
    – goldilocks
    Nov 2, 2021 at 19:46
  • 2) You will then be able to detach from the session while the program is running without interrupting it, using the keyboard controls described above. It will continue running by itself to whatever extent it normally would; 3) You can then re-attach to the session from anywhere you are logged in (remote, local, serial, whatever) and find the programming running normally. You can start a session from anywhere and re-attach it from anywhere, the sessions are idenified by the user and the label used to create them. If not terminated they last as long as the system is up.
    – goldilocks
    Nov 2, 2021 at 19:46
  • Thank you for this - much appreciated.
    – inni
    Nov 3, 2021 at 23:28
  • Just another question for you - if we connect the raspberry pi to a touchscreen with a built in PC, how can we view what is showing on the raspberry pi on the PC/touchscreen and control the program using the touchscreen? We have tried video capture using a HDMI Video Capture Card but we can't quite get the resolution right / to match the raspberry pi screen which means the program won't work properly as the buttons wont be in the right position. Is there any other way we could achieve this?
    – inni
    Nov 3, 2021 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.