As pointed out elsewhere, dd-ing over a running OS is never a good idea. An alternative (and the usual way you'd develop embedded systems) is to have your OS image served from a network drive and the target board perform a network boot. This speeds up the initial development and you only need to write out the SD cards as you get closer to completion and need ...
Use with caution
This works for me because I am using a read-only root filesystem with a custom Buildroot OS. This script hasn't been tested on Raspbian yet, but will probably work.
echo "Copying image to RPi..."
sshpass -p PASSWORD scp /PATH/TO/SDCARD.img USER@RPI:/tmp/sdcard.img
echo "Flashing image to /dev/mmvblk0 on RPi..."
I made this little library, fedeb95/pin that proved useful for me. Lacks some features, but if it suits you... it worked for me.
Edit: pin is a RPi.GPIO wrapper. Instead of calling method x of RPi.GPIO you call method x of pin. You can specify in a configuration file if your program is running in test mode (wyere you read random values from pins, or values ...
Your code snippet is not as simple as you may think.
Environment variables are set separately for each process (possibly with inheritance), so if you set MY_ENV_VAR in a shell and test for it from the same shell (with Python code or otherwise) it will be set. If you run Python from a different shell, it won't be. Even in the same shell, you may lose ...
Use an SD card large enough to hold multiple partitions
The SD card should hold a boot partition (0) and three OS partitions (1-3).
The boot loader on the boot partition would examine the partition labels to determine what to load. Suppose the labels are:
The loader knows to load the OS from partition ...
The closest thing I've ever heard of like this would be Midnight Commander.
GNU Midnight Commander is a visual file manager[...]. It's a feature
rich full-screen text mode application that allows you to copy, move
and delete files and whole directory trees, search for files and run
commands in the subshell. Internal viewer and editor are included.
Here a rough approach:
Replace /sbin/init with upgrade tool.
Tell init to re-exec itself.
Kill all other remaining processes (for example with kill -9 -1)
Use pivot_root and chroot to replace the root filesystem.
If necessary exec the next stage to drop references the old root.
Recursively unmount the old root.
Write the new image.
You could ssh over usb. https://desertbot.io/blog/ssh-into-pi-zero-over-usb
Or you can configure the pi to connect to your phone, and do the same with the laptop for wireless ssh.
If you are not using the GPIO or any other pi specific hardware, then really you could just write/test your code in a vm (there is even a x86 version of raspian if you want!) ...
If you want to develop C/C++, you can use Eclipse CDT, once installed and with the right toolchain you will be able to code on your PC, then compile on your PC, send the binary file and remote debug. All from your PC without touching the raspberry.
Raspberry Linux toolchain (if you can work on Windows there is SYSGCC toolchain)
I'd approach this by trying to craft a Makefile recipe to carry out the steps you want, including passing the binary to be tested as a command to ssh. Something along the lines of (note that this is totally untested and probably overly complicated):
i found this link which explains the process i think but i haven't tried it for myself (yet).
you need to add the mono repository using the commands shown (see link) and then you can just do sudo apt-get install monodevelop
hope this helps.