Skip to main content

I'm looking for a way to execute a workbench from a python script. I came across a sample py code from the fme knowledge center and I tried it (see py code below). It first gave me a win 32 error. My python is 32 bit. So, I downloaded python 64 bit, but still can't access the fmeobjects. see error message below. The fmeobjects does exist in the path below. What am I missing? How to execute a fme workbench from python?

 

........error message running the py script.....

 

import fmeobjects

ImportError: DLL load failed: The specified procedure could not be found.

 

.......... py code...........

import sys

sys.path.append(r"C:\\Program Files\\FME\\fmeobjects\\python27")

import fmeobjects

# initiate FMEWorkspaceRunner Class

runner = fmeobjects.FMEWorkspaceRunner()

# Full path to Workspace, example comes from the FME 2014 Training Full Dataset

workspace = 'C:\\Program Files\\FME\\fme.exe" C:\\...myworkbench.fmw'

# Set workspace parameters by creating a dictionary of name value pairs

parameters = {}

parameterse'Input'] ='C:\\...my input txt file'

parameterse'COORDSYS'] = 'LL-WGS84'

parameterse'Output_Name'] = 'My output filename'

# Use Try so we can get FME Exception

try:

# Run Workspace with parameters set in above directory

runner.runWithParameters(workspace, parameters)

# or use promptRun to prompt for published parameters

#runner.promptRun(workspace)

except fmeobjects.FMEException as ex:

# Print out FME Exception if workspace failed

print ex.message

else:

#Tell user the workspace ran

print('The Workspace %s ran successfully'.format(workspace))

# get rid of FMEWorkspace runner so we don't leave an FME process running

runner = None

Can you perhaps edit your question to use code formatting? It's difficult to make sense of Python scripts without proper indents.


I copied it here again with indentation. It failed at the import fmeobjects line. There is a fmeobjects.pyd under the c:\program files\FME\fmeobjects\python27. Is this the right directory to import fmeobjects? Do we need to import fmeobjects if we launch a workbench from the fme server? will it be easier to call the fme server? 

import sys
sys.path.append(r"C:\Program Files\FME\fmeobjects\python27")

import fmeobjects
# initiate FMEWorkspaceRunner Class
runner = fmeobjects.FMEWorkspaceRunner()
# Full path to Workspace, example comes from the FME 2014 Training Full Dataset
workspace = 'C:\Program Files\FME\fme.exe" C:\...myworkbench.fmw"'
# Set workspace parameters by creating a dictionary of name value pairs
parameters = {}
parametersÂ'Input_XYZ'] ='C:\...my input txt file'
parameters 'COORDSYS'] = 'LL-WGS84'
parametersu'Output_Name'] = 'My output filename'
# Use Try so we can get FME Exception
try:
    # Run Workspace with parameters set in above directory
    runner.runWithParameters(workspace, parameters)
    # or use promptRun to prompt for published parameters
    #runner.promptRun(workspace)
except fmeobjects.FMEException as ex:
    # Print out FME Exception if workspace failed
    print ex.message
else:
    #Tell user the workspace ran
    print('The Workspace %s ran successfully'.format(workspace))
# get rid of FMEWorkspace runner so we don't leave an FME process running
runner = None

I'm guessing you looked at this one?

https://gis.stackexchange.com/questions/286968/use-command-line-to-call-an-fme-workbench-from-a-python-tool-in-arcgis

I'm not quite sure I see the need for using fmeobjects for this, I would simply use the subprocess module, e.g.

import subprocess 

args = pr"C:\FME\fme.exe", "version"]
subprocess.Popen(args)

If you execute your workspace manually once, you'll find the exact command line syntax at the very top of the FME log window.

Also, just out of curiosity, what's up with this line:

workspace = 'C:\Program Files\FME\fme.exe" C:\...myworkbench.fmw"'

Hopyfully it's a typing error? If not, it could explain the issue.


I copied it here again with indentation. It failed at the import fmeobjects line. There is a fmeobjects.pyd under the c:\program files\FME\fmeobjects\python27. Is this the right directory to import fmeobjects? Do we need to import fmeobjects if we launch a workbench from the fme server? will it be easier to call the fme server? 

import sys
sys.path.append(r"C:\Program Files\FME\fmeobjects\python27")

import fmeobjects
# initiate FMEWorkspaceRunner Class
runner = fmeobjects.FMEWorkspaceRunner()
# Full path to Workspace, example comes from the FME 2014 Training Full Dataset
workspace = 'C:\Program Files\FME\fme.exe" C:\...myworkbench.fmw"'
# Set workspace parameters by creating a dictionary of name value pairs
parameters = {}
parametersÂ'Input_XYZ'] ='C:\...my input txt file'
parameters 'COORDSYS'] = 'LL-WGS84'
parametersu'Output_Name'] = 'My output filename'
# Use Try so we can get FME Exception
try:
    # Run Workspace with parameters set in above directory
    runner.runWithParameters(workspace, parameters)
    # or use promptRun to prompt for published parameters
    #runner.promptRun(workspace)
except fmeobjects.FMEException as ex:
    # Print out FME Exception if workspace failed
    print ex.message
else:
    #Tell user the workspace ran
    print('The Workspace %s ran successfully'.format(workspace))
# get rid of FMEWorkspace runner so we don't leave an FME process running
runner = None

Thanks. But I can't read subprocess either. The subprocess file is under the python folder. I don't understand why it's complaining about subprocess not found. The fmeobjects.pyd is also under the path I specified but keep getting error about not finding fmeobjects. I can run the workbench at the command prompt but I'd like to run from a python script. 


Hi @kit

You should not use the FMEWorkspaceRunner class to run workspaces on FME Server as mentioned in the following article: https://knowledge.safe.com/articles/302/errors-fmeworkspacerunner-python-errors-fmeobjects.html Please use the FME Server REST API instead.

If you would like to run your workspace in a non-FME Server environment with a Python script, can you please try modifying your Python script as below?

import sys
import os

sys.path.append(r"C:\Program Files\FME\fmeobjects\python27")

#Add the following line. The path should be your FME installation directory  
os.chdir(r"C:\Program Files\FME") 

import fmeobjects 
# initiate FMEWorkspaceRunner Class
runner = fmeobjects.FMEWorkspaceRunner()

#Add the rest of your script here

Reply