Question

getting the processing status of a FME workbench called by a python script

  • 22 March 2021
  • 1 reply
  • 15 views

Badge +7

I am looking for the possibility to process the status message of a FME script (Translation SUCESSFULL / Translation FAILED) within a Python script, or to stop the script as soon as the processing was not successful.

Currently I call my workbench inside a Python loop and process a (first) part of the data. Then I call the Workbench with the next part of my data and so on. Unfortunately, with my current workflow, I have no way to see when my Workbench generates an error in between and actually terminates. Within my loop, it continues and moves on to the next part.

Currently I generate my argument using a function:

def get_arguments(GDB, CSV, Start_Object_ID, Last_Object_ID):
    arguments = []
    if GDB:
        arguments.append('--DestDataset_GEODATABASE_FILE "{}"'.format(GDB))
    if CSV:
        arguments.append('--DestDataset_CSV2 "{}"'.format(CSV))        
    if Start_Object_ID:
        arguments.append('--Start_Object_ID "{}"'.format(Start_Object_ID))
    if Last_Object_ID:
        arguments.append('--Last_Object_ID "{}"'.format(Last_Object_ID))
    if resolution:
        arguments.append('--Resolution "{}"'.format(resolution))
    if Objektart:
        arguments.append('--Objektart "{}"'.format(Objektart))
      
    argument = ' '.join(arguments)                         
    return(argument)

Then I call my workbench with another function and pass my previously generated argument.

def fme_workbench(workbench, argument):
    directory_creator(FME_working_dir)
    FME_command = '"C:\Program Files\\FME\\fme.exe" ' + workbench + ' ' + argument
    print('\n' + FME_command + '\n')
    result = subprocess.Popen(FME_command)
    result.wait()

After the start, the command line opens and the Workbench is executed. When it is finished, the command line closes and the next data part is processed, regardless of whether an error occurred in the previous calculation.

Is there a possibility to check the output of the command line for keywords and depending on them to stop the script or to execute certain other functions?

 


1 reply

Userlevel 4

You can check the exit (return) code from fme.exe: 0 = success and -1 = failure.

See also https://docs.safe.com/fme/2020.0/html/FME_CommandLine/

 

Reply