The free firstobject XML editor has some command line switches. Here is the summary; details are below.
Switch | Purpose |
---|---|
-new | open in a new instance of the editor (useful when single instance preference is selected) |
-same | open in the existing instance of the editor |
-watch "C:\event.log" | open file in read-only auto-reloading mode to view the tail of log files |
-line 23 | open file at a line |
-offset 451 | UTF-8 offset from beginning of document or from beginning of line if line is specified |
-fromoffset 5 | pre-select text from this offset to specified offset |
-run script.foal:f arg1 arg2 | execute the script without showing the editor |
Examples:
foxe.exe "C:\XML examples\file.xml" -line 6
foxe.exe file.xml -line 6 -offset 5
foxe.exe -offset 240 -fromoffset 235 file.xml
foxe.exe -watch C:\event.log
foxe.exe -run C:\script.foal
foxe.exe -same file.xml
"C:\Program Files\firstobject\foxe.exe" -new file.xml
As of release 2.4.1 the free firstobject XML editor has a command line switch to run a script:
foxe -run "C:\foal scripts\script.foal"
It generates 2 files, foxe_err.txt and foxe_out.txt. The err file contains marked up information about the run and can help diagnose issues with running. The out file contains the output returned from the script in the return statement.
And with release 2.4.2 you can specify function and arguments, see below.
Run from command line problem
Garth Lancaster 19-Jul-2010
In foxe I can do this [with a foal script]
str NavigateIterativelyXYZ_Generated( CMarkup mDocToNavigate ) { mDocToNavigate.ResetPos(); str sXML = mDocToNavigate.GetDocFormatted(0); return sXML; }
so when I run it, a window pops up and asks which document I wish to convert, shows me the output, all is good... except now, I wish to do this from a command line.
foxe –run align0.foal input.xml output.xml
Where align0.foal contains the foal program, input and output names will likely come from a batch script % parameter or such, and input.xml will contain the streamed xml and output.xml will contain the results of the GetDocFormatted(0)
. I'm thinking foal can be very powerful, am I missing a point in its implementation?
Update April 23, 2011: With release 2.4.2, it works the way it should (the way Garth described). The -run command line option passes any number of command line arguments into the parameters of the function in the foal script. For example (remember to use quotes if a path or argument contains spaces):
foxe -run "C:\foal scripts\script.foal" C:\in.xml C:\out.xml
Here is a script to format XML that works with the previous command line:
formatxml(str sInPath, str sOutPath) { CMarkup m, r; r.AddElem( "load", sInPath ); m.Load( sInPath ); r.AddSubDoc( m.GetResult() ); if ( ! m.SetDoc(m.GetDocFormatted()) ) r.AddSubDoc( m.GetResult() ); r.AddElem( "save", sOutPath ); m.Save(sOutPath); r.AddSubDoc( m.GetResult() ); return r; }
Bascially this script just loads the input file, calls GetDocFormatted and saves to the output file (you could also add an argument to pass format flags). In addition it returns the results in case something goes awry you can see what happened in foxe_out.txt. If there is no problem, it might look like this:
<load>C:\in.xml</load>
<read encoding="UTF-8" length="31579"/>
<save>C:\out.xml</save>
<write encoding="UTF-8" length="29958"/>
If there are multiple functions in a script, you can name your entry function main
to avoid confusion about which function is being called. You can also specify the entry function explicitly on the command line with :function
at the end of the script filename. Specifying the function allows you to invoke multiple functions in one script from the command line. Here is an example of using the same script to perform different operations:
foxe -run C:\script.foal:extract London
foxe -run C:\script.foal:merge London "New York"
If you specify a function name that is not found in the script, there will be an indication at the bottom of foxe_err.txt that also indicates the entry point it would have used if you had not specified one:
<entry_point arg_count="2" not_found="gormatxml">formatxml</entry_point>
If you do not specify the function and there is no main function in the script, the last function with a matching number of arguments is called. It chooses the last matching function because functions earlier in the script tend to be subroutines since in FOAL you can only call functions below where they are defined.
Quoted Command Line Param Bug?
Tim Johnston 20-Jun-2011
It would seem there is a problem when running a FOXE script from the command line where the quoted parameter (such as a folder path) has a trailing slash, then the script fails... [this is a command console issue rather than a foxe issue, and he answered his own question in a subsequent email] It seems if you leave off the trailing slash and check for it/add it in the script it works fine. It also seems you can end it with a double back slash and it correctly escapes it - go figure :)
Incidentally, this failure doesn’t affect the return code of the process – I assume it would/should, but doing an echo %errorlevel% returns 0 after the failure... Also, would it be possible to make the FOXE command line not return back to the prompt before it is finished? i.e. make it "modal"? Basically when you run a script, control immediately returns back to the calling process and if the remaining batch file etc. is relying on the output of the FOXE script, then it is not there (as its still processing) – or at least do you think you could add a command line option to not return until processing is complete?
Thanks for the help on escaping the trailing backslash in the command line. I think you should be able to make the foxe.exe call wait using the START /WAIT command to launch it. By default batch files wait, but windowing programs do not so you have to use the START command in that case.
How to run script automatically
Angela Baines 18-Jan-2010
The foal script works a treat now. When I move this to production it has to run as part of an automated project that will be scheduled to run overnight