Can I run scripts when VSCode boots and closes? - visual-studio-code

I'm developing on a VM and I'd like to automate booting and shutting down the VM whenever I launch VSCode into this project (over ssh).
I got around having to boot the VM by creating a script that launched the VM then VSCode. I use that to launch VSCode instead of the start menu whenever I want to work on this project. However, this solution doesn't work for shutting down the VM when I'm done.
Is there any way to accomplish this? Maybe some project setting that would execute a shutdown script on the VM when I disconnect, or some way I could hook up a script to run on my machine when VSCode closes that would shut down the VM?
Is there any way to avoid the janky startup script? Can I run a script when VSCode launches as well?

According to Visual Studio Code issue #10044 https://github.com/Microsoft/vscode/issues/10044, there is no way to run a script automatically from inside VSCode at startup unless you are willing to write an extension. Even if you are going to write an extension according to the API documentation https://code.visualstudio.com/api/references/activation-events for VSCode, There is no event for when shutdown occurs.
EDIT: Although it is not possible to do this within VScode alone, you could write a wrapper script when starting and exiting to to run the command.

Related

Embedded terminal processes die if I close the IDE, how to have them continue running?

A novice question... but please help.
I often run "stuff" in the VS code terminal, things like local webapps being served on localhost, scheduled process, etc...
Note: I'm on windows
The workflow is something like:
Turn on computer
Open VS Code
Open the integrated terminal in VS Code (using gitbash)
Run bash start.sh where start.sh is a script that starts some "long-running" processes (eg. Airflow, Streamlit apps, etc...)
The problem is:
If I close VS code the processes die
If I reboot the computer the processes don't restart
I have 'a' solution, but I don't like it:
Build these into docker containers and have these managed by the docker deamon
It seems overkill for quick things that I just want to have running.
So, is there a way to have things from the VS Code terminal "survive/restart" a VS Code close/computer reboot?

Using tmux in VS Remote SSH session

I am currently starting to work with SNNs on a GPU server. I am working with VS Code Remote-SSH package. Thereby, I'd like to use the tmux package to be able to start multiple processes which don't terminate when I disconnect the terminal from the server.
So far I used the https://cppdev.medium.com/vs-code-and-tmux-intergation-for-reliable-remote-development-e26594e6757a Tutorial. It already helps me that the process, I run doesn't shut down when I close the terminal but I didn't manage to start a second process on the server because each time, I open a new terminal, the already running process appears. What are your thoughts on that?
Thanks

Run a local command before starting eclipse debugging

I want to run a terminal command just before a debug configuration starts on Eclipse.
I heard about CDT launch Groups, but couldnt get around it fully. I need to just run a normal terminal command, nothing fancy.
The aim is to copy some stuff over to the execution path before actually starting the debugging.
I managed to do this via "Launch Groups" in the CDT. Creating 2 groups, one as a c/C++ Application which calls a shell script that includes the command I want to run. And then the normal debug configuration I wanted to execute.

PowerShell open remote GUI session for UIAutomation

I'm currently working on automatic installation of GUI application using library UIAutomation PS Extensions (https://uiautomation.codeplex.com/). It works pretty well in cases, when I run it against existing Windows user session. I run my PS script, it opens a window and I can click on buttons and so on ..
However, problem raises when this library is called from remote machine. I call my script (which should open a GUI window and start controlling it) via PsExec from remote machine. This causes that script is not able to open GUI window on remote machine and starts to produce various exceptions.
As workaround for this, I can make PsExec to connect to specific existing session on remote host, but unfortunatelly this is not stable as I can't guarantee session's existence.
Does enyone know whether it's possible to force PowerShell to open new session (interactive GUI) through which I would be able to call UIAutomation commands?
Thank in advance
Matthew
I'm not clear on whether it's feasible to remotely open a new interactive desktop session in which to run GUI tests that require one. I'd be interested to find out if it's doable, since problems like this frequently come up when folks try to set up CI tests of Windows GUI apps.
Alternatively, I'd propose solving this by configuring the machine where your tests run to log in as a user at boot. Then you can remotely launch your tests as that user, and make use of their open session. That's worked in the past for me when I've run into similar issues.

How to do remote debugging in Eclipse CDT without running `gdbserver` manually on the target every time?

Before each debugging cycle I have to run gdbserver on remote target (Linux). So I was thinking to make script that would call python program that would connect over ssh and would run gdbserver.
I cant find any options to run command before debug and I also try to change .gdbinit file but I am unable tu run python script whit that. Since I am using crosscompiler I cant to get other gdb whit such support.
You don't need to run Python to invoke an external command from GDB. This (in .gdbinit) should work:
shell ssh remote-host gdbserver :12345 /path/to/binary/on/remote &
target remote remote-host:12345
If you do need more complicated ssh setup and need Python for that, you can certainly get it with
shell python your_script.py
If you can't get any external program called from your gdbinit, I see one way of doing it within Eclipse that might work (I didn't tested) but it is not really straightforward...
Create an External Tool configuration that launches your gdbserver program (Python or whatever command line script)
Create a C/C++ application launcher that launch your application to debug
Create a launch group that will call the two previously configured configurations.
Launch the group in debug mode
Eclipse 4.7.0 can connect to SSH and launch gdbserver automatically with the automatic launcher set when creating a new debug connection, without the need for any custom scripts.
I have explained the setup in great detail at: Remote debugging C++ applications with Eclipse CDT/RSE/RDT