How can I execute a .bat file when Blender starts?

I have to start a postgresql server when blender starts. To start the server I use a .bat file I start manually.

I want to automatically start the server (execute the .bat) when Blender starts. I tried this script but it not working. ideas? thank you

import subprocess
filepath="C:\Users\PORTABLE\Desktop\pgsql_binaire\pgsql	est.bat"
p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)
stdout, stderr = p.communicate()


Couldn’t you have the .bat start the server and then Blender?
Then just run the bat when you want to start blender.

Just an idea :slight_smile:

thank you for the idea
Yes, I have thought about it but the problem is that I can not run a blend file directly. I mean that I will be forced to start with .bat blender and then open my Blend files!!

I answer my question. Here is a code that works for me:

import bpy
import os