Tuesday, 5 April 2016

Run FME workspace using python


errorI'm trying to run a second workspace using python command in "Shutdown Python Script" in the first workspace using the following command. But its giving me an error. Is there anything I need to do different? I am using FME 2012 SP 2


Thanks, Sam



So as suggested by Safe tech support, I created a batch file with the following code:


fme.exe c:\test2.fmw --SourceDataset_ARCGIS_LAYER C:\ScratchParcel\DevEnv.gdb\AddressPoint --DestDataset_SHAPE C:\temp


and added the following code in the shutdown python script window:


import os os.system("C:\\temp\\test.bat")


When I run it, although it says transaction was successful, I don't get any results i.e., the output shapefile is not created.



Answer



Your Python doesn't look syntactically valid. Try


import os
os.system("fme.exe C:\\temp\\test2.fmw --SourceDataset_ARCGIS_LAYER C:\\ScratchParcel\\DevEnv.gdb\\AddressPoint --DestDataset_SHAPE C:\\temp")


I've added the parens and quotes around the string you are passing to os.system, and escaped the backslashes.


Update: In addition, the fme.exe in your path is different than the fme.exe being run by Workbench. Explicitly specify the path to the fme.exe you want to run:


os.system("c:\\pathToFme\\fme.exe test2.fmw")

or, perhaps in this more future proof manner


os.system(os.path.join(os.environ['FME_HOME'], "fme.exe") + " test2.fmw")

which says "run using the fme.exe that we are currently running".


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...