Running bench command from code

Dear friends,

Is there any possibility to run a bench command from code (js or py)? For example from a button.
If can, what is the structure of the code?

Thank you

1 Like

Looking for the same , did you happen to find a way ?

Hello, We can run any command through python using library called OS. Also you can give full path where frappe folder is exist. Or before os.system go to that folder through chdir()

import os

os.system('bench start')

Or

import subprocess

subprocess.run('bench start', shell=True)

Most bench commands in Framework are just functions in app/commands/<file>.py files.

You can call the relevant function instead calling it from shell. Don’t run the command function directly, copy the relevant part of command body instead. E.g. bench build command just calls another function called bundle


If they are defined in bench then you can’t import them directly like this. Only way to run those would be subprocess call.