Batch Processing Method 2: Command File

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

Type FME within a Command Prompt and you will see one of the command options for FME is…

fme COMMAND_FILE <commandFile>


The Command File is a file containing a list of FME related commands, one command per line. Line continuation characters (\) can be used to split commands over several physical lines in the file. The commands that can be processed in this way are: mapping file generation, running a workspace or mapping file, and even executing another batch file.

For example, the command file might contain lines like:

c:\dxf2dgn.fmw --SourceDataset c:\in1.dxf --DestDataset c:\out1.dgn LOG_FILENAME c:\fme.log 

Note you don’t need to prefix the command with ‘fme’ because FME was already started when you gave the command “fme COMMAND_FILE <commandFile>?

The LOG_FILENAME keyword is optional, but permits a log file to be written so is recommended.

So inserting several commands into a Command File gives you a "batch" file which can be executed using the fme command above, or by putting that command itself into a *.bat file.

Multiple Datasets

Multiple dataset commands include more than one dataset per reader, for example:

fme.exe c:\temp\command.fmw --SourceDataset_ACAD """"C:\FMEData\Data\Water\distribution_L25.dwg" "C:\FMEData\Data\Water\distribution_L26.dwg"""" --DestDataset_DGNV8 c:\temp\output.dgn


While this runs acceptably on a plain command line, it will fail inside a command file because the parser will misinterpret the number of items on the command line.

Ultimately, FME, in its mapping file, needs to see something like this:

""C:\dale\data\testSuper\fc.shp" "C:\dale\data\testSuper\mplan.shp""


...ie double set of quotes at the beginning and the end of the whole list, and only one quote at the end and beginning of each internal filename.

To get the desired result here you need to put a \ in front of every quote in what you ultimately want in the mapping file, and then a " at the beginning and end of all that. So the syntax you need to use would be:

fme.exe c:\temp\command.fmw --SourceDataset_ACAD "\"\"C:\FMEData\Data\Water\distribution_L25.dwg\" \"C:\FMEData\Data\Water\distribution_L26.dwg\"\"" --DestDataset_DGNV8 c:\temp\output.dgn



That method is bomb-proof, but if your datasets don't have a space character, and you want a quicker solution, then FME only has to see:

 "C:\dale\data\testSuper\fc.shp C:\dale\data\testSuper\mplan.shp"


which would mean in the command file having:

"\"C:\dale\data\testSuper\fc.shp C:\dale\data\testSuper\mplan.shp\""

 

Python Versions

A single instance of fme.exe can only ever load one Python interpreter. This means in order for a Command File to execute all workspaces listed in the Command File, the workspace Python Interpreter value set in Workspace Parameters > Advanced > Python Interpreter needs to be compatible for all workspaces (e.g. all 3.x+).
If a mismatch in compatibility is detected while the Command File is run, then the translation will fail with an error message and the running of the Command File will end at that workspace.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.