Cannot execute .bat file

image
I failed to execute the .bat file when running workflow with services but successfully execute by debugs mode. May i know the reason?

*The input files has no relation with the execution program. I just wanna use them to trigger the program.


The log shows that the external program run successfully too.

Hi @ceci_cheung,

Can you let us know please what you would like to achieve by the batch file? Is it possible for you to share the to the batch file added commands?

Sure. My batch file is just used for execute a python program like below


And the python program is mainly use for extract the patients detail to csv. So, the result should give a csv when i run the workflow.

Hi @ceci_cheung,

Do you know if the external program (Python script) “modifies the job file using the full path”? Because this is important, as mentioned on the online PlanetPress Workflow 2021.1 User Guide website:

Output

If the external program modifies the job file using the full path, the modified file is the output of this software. Otherwise, the output is the same as the input. Metadata is not modified in any way. Job Infos may be modified, depending on the options set in the task’s properties.

Source: ‘External Program - PlanetPress Workflow 2021.1 User Guide’

I suppose that the selected data sample file isn’t the CSV file which you expect to be the output of the External Program plugin when you run the Workflow process in Debug mode?

P.S. Please note that you can also execute Python code by the Run Script plugin

@Marten
The external program will not modifies the job file. Cause i have already copied the DCM file to another folder (which will be modified using full path by python program) before put it into planetpress input folder. So they should be two different files. The only use for the job file is to execute the external program.
The CSV file is what i expected to have in debug mode.
Except running the services, the whole setting is same with debug mode. That’s why i have no idea what i am missing.:face_with_raised_eyebrow:

And I tried to put .py file in external program plugin but seems it cannot run it no matter by debugs or services.

@ceci_cheung,

To be able to run a .py file, Windows is relying on environment variables (and file association settings) that tell it .py files are associated with a Python executable and where that executable is located on your system. Those environment variables and file associations exist when you are interactively logged on to your system. However, they may not exist in the account that Workflow is using to run the service.
Your batch file should therefore set those environment variables before running the Python script and it should probably also specify the full path to the executable that runs the script.

That being said, Marten mentioned that you can run Python code directly from the Run Script task (which you have misunderstood as the Run External task). However, to run Python directly from Workflow you must make sure to use ActivePython. Learn more about this on this page.

1 Like

@Phil
Thanks and clear explanation. So i can try using run script for python code if i failed to run .bat files in running external program.
But i am still wired why i can’t run external program when i started the services.

I just realized that you are calling the batch file directly. You should call the CMD executable instead, and pass the batch file name as well as the data file as parameters:

Make sure to set the Start In folder to the correct location on your system.

@Phil
Could you please help have a look on what i do is correct or not?

  1. I put the bat filename by script in jobinfo1.
  1. And i use it as parameter in external program properties:

*I do this because my input file is dicom file and it dosen’t contain the bat file name.

However, when i run the debug mode, it load at external program plugin so long.

The Parameters field in the External Program task should therefore contain:

/c %1 "F"

where::
/c : instructs CMD to run the command and then terminate
%1 : contains the name of the batch file that CMD runs
"%F" : contains the full path and file name of the data file you captured in step 1 of the process.

Oh I see. Thanks for your clear explanation! @Phil
But it’s still failed when i run it by services. But the log shows no error when i run the workflow.:thinking:

  • Same as before, i run it successfully by debug tools.

Then you are certainly missing the proper environment variables to be able to run Python scripts from a service, as I explained in my very first reply. And it would all be so much easier if you installed ActivePython, as I also stated then.

At this stage, I recommend you open a call with our Technical support team so they can investigate with you.

1 Like