Now an UltraEdit script is executed from the command line with:
uedit64.exe /s="J:\SkyDrive\work\ue-script\newFile.js"
Is it possible to pass parameters to UltraEdit script from command line? And how do I get them in the script?
Maybe like this:
uedit64.exe /s="J:\SkyDrive\work\ue-script\newFile.js" /pars="parameter1=value1,parameter2=value2"
And then get parameter1=value1
and parameter2=value2
in newFile.js
.
UltraEdit scripts are executed usually from the command line to reformat one or more text files completely without user interaction and without depending on parameters. Or an UltraEdit script is started manually by a user from within UltraEdit without or with some minimal user interaction using
getString
and/orgetValue
. There are many scripting languages and script interpreters for doing something depending on parameters like VBScript, PowerShell, Perl, Python, etc.It is not possible to specify additional custom parameters for an UltraEdit macro/script on the command line of UltraEdit. The command line arguments are interpreted by
uedit64.exe
oruedit32.exe
and UltraEdit macros and scripts don't have access to arguments list of the executable.I'm aware of three possibilities to pass strings (parameters) to an UltraEdit script from another process before starting UltraEdit and executing the script:
1. Pass parameters to an UltraEdit/UEStudio script via the clipboard
The first solution is easy to implement. But it has the big disadvantage that Windows clipboard content is modified on starting and no other process should copy something to the clipboard before the parameters and their values are read by the script. These disadvantages are very problematic if UltraEdit should be executed in the background for executing the script.
The following two commands must be executed on the command line or in a batch file:
clip.exe
has been available since Windows Vista and Windows Server 2003. But there is noclip.exe
on Windows XP. However,clip.exe
from Windows Server 2003 can be also used on Windows XP.It is highly recommended to use
/fni
(force new instance) on starting UltraEdit for executing a script from the command line when the configuration setting Allow multiple instances is not checked as by default. For an explanation why/fni
should be used as the first parameter on the command line on running an UltraEdit macro/script from the command line, read topic Always get error message when running a macro/script via command line parameter (solved) in the UltraEdit forum.An example script code for reading the parameters from clipboard is:
2. Pass parameters to UltraEdit/UEStudio script via a text file
In comparison to the first solution the clipboard is not modified by using this solution. However, it must be made sure that the following command lines are not executed at the same time by two processes.
The line output by command ECHO is redirected into text file
C:\Temp\ParameterList.tmp
, and then UltraEdit is started for running the script in a separate process and batch processing is halted until UltraEdit is exited. Finally, the temporary text file is deleted from the command line.Example script code for reading the parameters from file with fixed name and path:
For usage of a dynamic file name, the file name must be specified as the second parameter to open this file by UltraEdit before running the script and the script reads the parameters from the first opened file.
The script code for this solution could be something like:
3. Modifying the script before execution
An UltraEdit script file is an ANSI text file and therefore it is possible to modify the script before execution.
The JavaScript code line which defines an initialized array of strings is first written into a temporary file. This temporary file is copied together with the script file to a new script in folder for temporary files. UltraEdit is executed using the temporary script file with the added parameter list array. Finally both temporary files are deleted from the command line.
An example script code which is extended dynamically with an additional line at the top to define the parameter strings:
The advantage of this approach is that instead of an array of parameter strings it is also possible to define an array of integer numbers or floating point numbers. Or on the command line, multiple variables of different types are defined which are added to the temporary script file.
A last variant would be using
// include parameters.js
at top of the script file and the fileparameters.js
(with complete path or without path) is created dynamically on command line containing the lines to define the parameters in JavaScript language as JavaScript variables.