Try ERPNext Buy Support Partners Foundation

Passing argument to bench execute

Hello, is it possible to call a function that expects arguments with bench execute?


use, --args or --kargs options to pass the arguments

e.g. bench execute --args "arg1, arg2, .., argN" method_name

for more information please check, bench execute --help

Thanks, Makarand


OK thanks got it

In my case bench execute --args β€œarg1” was not working
instead I used bench execute --args β€œ{β€˜arg1’}” this worked for me.


Thank you. We should mention it in the docs.

This worked for me:

bench --site  execute  --args "{'My Company Name'}" myApp.myApp.doctype.myDocType.myPythonModule.myMethod
erpdev@djst:~/frappe-bench-DJST$ tree -L 1 apps
β”œβ”€β”€ erpnext
β”œβ”€β”€ frappe
└── myApp
    └── myApp
        └── doctype
            └── myDocType
                └── myPythonModule

Where myPythonModule is a file containing a method:

def myMethod(company):
  msg = "Result :: {}".format("Ok")
  return { "returned": msg }

Output is:

{"returned": "Result :: Ok"}

Fun fact: unlike many bench commands it is not necessary to run it from the bench root directory

1 Like