How to call python script from Groovy and the python script in turn calls another python script


I am trying to call the python script from groovy and passing some command line arguments along with the command.

The command I found to execute python code from groovy is:

Groovy code :

"python I:\Researchwork\ ‘myname’ ‘count’ ".execute()


In my python script file, I am taking the arguments and making a text file using this arguments. After this I am calling one more script file from the same file.

Code of python script:

import sys, optparse, os

import subprocess

if __name__ == '__main__':

    # Count the arguments

    open('file.txt', 'w').close()

    with open('file.txt', 'a') as file:        


"python 'file.txt' 'foldername' ", shell=True)

    print("Done") :

This file takes in the file.txt and foldername and does my work

Here file.txt is a file where I am storing the text and passing this file.txt name and the foldername to call my second python script file using

My problem is,

  • The groovy code is able to call the python script but the file.txt is not updating with the text from command line argument
  • The sub script in python script file is also not executing(i.e., file is not executing)

Please Kindly help me to solve the issue.

Thanks & Regards,

Hi @Jyothi_R,

I’ve never tried to call a Python script from Groovy before… But QuPath can be called directly from the command line and can run Groovy script from there as well. If you were to ‘translate’ your Python script to Groovy maybe this will be an easier and cleaner solution to run your tasks?

1 Like

My problem is solved.
Thanks for the ones who had a look at my problem to help me.

Thanks & Regards,