Question

run workbench from external python


I am using the following python code (from takashi) to run a workbench (Python 2.7 & FME 2013):

 

 

>import fmeobjects

 

>wr = fmeobjects.FMEWorkspaceRunner()

 

>wr.run('C:/blab/blabla.fmw')

 

 

It works fine but now i would like to get more infos about what was going on, like logfile message, numer of feature written and exit status... is it possible??

 

If yes, where can i find examples and docu? The local fmeobjects api docu do not mention FMEWorkspaceRunner etc...

 

 

I now i can get it to work and access all those infos via an embedded shut down python script, but i would like to do it the other way...

 


10 replies

Userlevel 4
Hi,

 

 

the fmeobjects API, including the FMEWorkspaceRunner is documented here:

 

<fme install dir>/fmeobjects/python/apidoc/index.html

 

 

You can override the log file name in the workspace, look in the Navigator under Workspace parameters / Log file. This parameter can be published like any other so that you can specify it from your script.

 

 

You can then later read and parse this file to get the number of features processed, etc.

 

 

David
Userlevel 2
Badge +17

Hi,

 

 

A log file is created whenever running a workspace; the log file name will be the same name as the workspace file name by default, e.g. "C:/blab/blabla.log". But I don't think it's possible to display log messages while running. Your goal is to use fmeobjects in external Python environment (outside of FME Workbench)? If so, my posts in this thread might help you. Python and Available Licences https://knowledge.safe.com/questions/3318/python-and-available-licences.html

 

Takashi
Thanks David,

 

 

I was hoping to find a way to use the fmeobjects API and not have to parse the logfile (this is the way we are using up to now...)

 

 

Is there a way to catch global variables like FME_FailureMessage or FME_Status (the way i would do it in an embedded shutdown python script) ??

 

 

import fmeobjects

 

wr = fmeobjects.FMEWorkspaceRunner()

 

wr.run('C:/blab/blabla.fmw')

 

if wr.FME_Status == 0:

 

   print FME_FailureMessage

 

   ...

 

 

I my API doc (<fme install dir>/fmeobjects/python/apidoc/index.html) there is nothing about FMEWorkspaceRunner...

 

The fmeobjects modules only shows 5 classes (exception/feature/geometry/logfile and session) and lots of variables.

 

Do i need to install something more than FME Desktop?

 

Userlevel 4
Hi,

 

 

I do not think it is possible to use the FMEWorkspaceRunner API that way, I'm afraid.

 

 

An option could be to use the Python shutdown script to write a special log file with only the necessary feature counts, etc, which you could then pick up and read from your Python script. Should be much simpler.

 

 

David
Userlevel 2
Badge +17
The complete documentation on FME Objects Python API would be copied in your machine if you selected SDK installation option while installing FME. I think you didn't select the option. Try re-installing FME. The SDK option can be selected on the installer window, maybe the 3rd or 4th step.
Userlevel 2
Badge +17
In fact, the FMEWorkspaceRunner object just launches "fme.exe", it will not collect or retain any running status. But "run" method throws an exception object when the workspace failed, so you can know if it failed or not. ----- # Example wr = fmeobjects.FMEWorkspaceRunner() try:     wr.run('C:/foo/bar.fmw')     print 'success' except fmeobjects.FMEException as ex:     print ex.message -----
Ok. Many thanks for your help!
thanks, great

Hi takashi,

You link above doesn't seem to be working anymore - any chance you could repost?

Userlevel 4
Badge +13

Hi takashi,

You link above doesn't seem to be working anymore - any chance you could repost?

Looks like these are now at https://knowledge.safe.com/questions/3318/python-and-available-licences.html (And I editted the old link as well)

Reply