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?

@RWEMA_Aimable,

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

4 Likes

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.

3 Likes

Thank you. We should mention it in the docs.

This worked for me:

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

Where myPythonModule is a file containing a method:

@frappe.whitelist()
def myMethod(company):
  msg = "Result :: {}".format("Ok")
  myLogger(msg)
  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