Running script from command line with arguments for the script

Running script from command line with arguments for the script


    Oct 11, 2013#1

    Is there a way to pass script arguments at the command line
    Something like the following
    ultraedit /s,e="c:\workingfiles\myscript.js arg1 arg2 arg3 arg4

    We have thousands of xml files (from outside vendor) that need to be reformatted with LF/CR. I have a script that does exactly what I want; but I have to invoke it from GUI and enter the arguments as prompted. I would love to have a way just execute this on the command line and have it work. Then I could use a batch file with the command line instruction in it.

    Of course it would be better yet if you had API and I could just call an ActiveX Object. HeHeHe!

    Thanks in advance,
    Pamela Reinskou VersusLaw Inc.

    Grand MasterGrand Master

      Oct 12, 2013#2

      Using Help - Index, activating tab Index, entering or searching in the list for Command Line Parameters and double clicking on this item in the help index opens the help ppage Command Line Parameters. The only available parameters are listed and explained on this help page.

      It is not possible to pass arguments to a script via command line arguments directly. But of course you can simply write the arguments for the script from within a batch file into a dynamically created text file located for example in directory %TEMP% and pass the full name of this text file on the command line. The script just needs to be written to search in the array of opened documents for the file with the parameters for the script, reads them and then processes all other files opened too.

      An example batch file:

      Code: Select all

      @echo off
      rem Write one script argument per line into the temporary file.
      echo argument 1 >"%TEMP%\ScriptParaFile.tmp"
      echo script parameter 2 >>"%TEMP%\ScriptParaFile.tmp"
      echo and so on >>"%TEMP%\ScriptParaFile.tmp"
      start "XML Processing" /wait /min "C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\uedit32.exe" /fni "%TEMP%\ScriptParaFile.tmp" "C:\Temp\*.xml" /s,e="C:\workingfiles\myscript.js"
      del "%TEMP%\ScriptParaFile.tmp" >nul
      And the example script file C:\workingfiles\myscript.js

      Code: Select all

      // Search for the file with the script parameters.
      // Usually it is the first opened file, but that can change.
      var nParaFile = -1;
      for (nDocIndex = 0; nDocIndex < UltraEdit.document.length; nDocIndex++)
         if (UltraEdit.document[nDocIndex].isName("myscript"))
            nParaFile = nDocIndex;
            // Delete all trailing spaces at end of all lines caused by a space
            // between echo string and redirecting > for better readability.
            // Select everything in the parameter file.
            // Is the parameter file not empty by mistake.
            if (UltraEdit.document[nParaFile].isSel())
               // There should be one script argument per line.
               var asArguments = UltraEdit.document[nParaFile].selection.split("\r\n");
               // Remove last element from array if this is an empty string
               // because the last line of the parameter file is also
               // terminated with carriage return + line-feed.
               if (asArguments[asArguments.length-1] == "") asArguments.pop();
               for (nArgument = 0; nArgument < asArguments.length; nArgument++)
                  UltraEdit.outputWindow.write("Argument "+(nArgument+1).toString()+" is: "+asArguments[nArgument]);
               // Assign the parameters to the variables of the script here.
      // Process now all other opened files.
      for (nDocIndex = 0; nDocIndex < UltraEdit.document.length; nDocIndex++)
         if(nDocIndex == nParaFile) continue;  // Skip the parameter file.
         // Do whatever should be done on the opened files.
      // Save all opened and modified files including the parameter file.