How to run ANY console or Windows application from within an UE script/macro?

How to run ANY console or Windows application from within an UE script/macro?

6,687587
Grand MasterGrand Master
6,687587

    Apr 16, 2010#1

    Some users have the requirement to run ANY tool from within a script or macro, but it is not possible to execute any command from within a macro or script directly. Here is a solution for that problem.

    Be aware that with this solution you could also execute commands like rd /s /q C:\ which is surely not what you want. Dynamically creating and executing commands is a high security risk.

    First you have to configure a user tool. Open Advanced - Tool Configuration and press the button Insert. Configure the user tool as follows:

    On tab Command:

    Menu item name: Any Console tool (for example)
    Command line: %sel%
    Working directory: (let it empty)
    Toolbar bitmap/icon: (let it empty or browse to a BMP, ICO, GIF, PNG or JPG file)

    On tab Options:

    Program type: DOS program
    Save active file: unchecked
    Save all files first: unchecked

    On tab Output:

    Command output: Output to list box
    Show DOS box: unchecked
    Capture output: checked
    Replace selected text with: Captured output

    That user tool is for all 16-bit DOS and 32-bit console applications with no user interactions during execution. When a user must enter something during execution of the tool, option Show DOS Box would be needed. As configured the output of the called tool is captured and replaces the current selection in the active file.

    To call any Windows application without the need that the macro or script waits until the called Windows application terminates, configure a user tool as follows:

    On tab Command:

    Menu item name: Any Windows tool (for example)
    Command line: %sel%
    Working directory: (let it empty)
    Toolbar bitmap/icon: (let it empty or browse to a BMP, ICO, GIF, PNG or JPG file)

    On tab Options:

    Program type: Windows program
    Save active file: unchecked
    Save all files first: unchecked

    On tab Output:

    Command output: Append to existing
    Show DOS box: unchecked
    Capture output: unchecked
    Replace selected text with: No replace

    Windows applications do not write to standard output and therefore nothing can be captured. Also Windows applications are started always as new task. So by default the Windows command line interpreter continues immediately resulting here with terminating itself immediately after calling the Windows application and UltraEdit/UEStudio continues execution of macro/script.

    When you want to run any Windows application, and you want that your macro/script executing the application should wait until the Windows application terminates itself, configure a user tool as follows:

    On tab Command:

    Menu item name: Any Windows tool (for example)
    Command line: start "UE Tool Execution" /wait %sel%
    Working directory: (let it empty)
    Toolbar bitmap/icon: (let it empty or browse to a BMP or ICO file)

    On tab Options:

    Program type: DOS program
    Save active file: unchecked
    Save all files first: unchecked

    On tab Output:

    Command output: Append to existing
    Show DOS box: unchecked
    Capture output: unchecked
    Replace selected text with: No replace

    Be aware that the Windows application is called via the Windows standard command start which is important to know when parameters must be passed to the Windows application, too.

    None of the 3 user tools saves files before execution. Do that from within the script or macro when needed before calling the tool. Take into account that a new file could be opened which require the Save As command.

    Now you can use scripts and macros to call any tool using the 3 user tools.

    Script template:

    Code: Select all

    var nActDocIndex = UltraEdit.activeDocumentIdx; // Requires UE v16.00 or later.
    // For an alternate method working for UE prior v16.00 see http://forums.ultraedit.com/viewtopic.php?f=52&t=4571#p16586
    // or just use the advanced function GetFileIndex posted at http://forums.ultraedit.com/viewtopic.php?f=52&t=4596#p26710
    UltraEdit.newFile();
    UltraEdit.activeDocument.unicodeToASCII();
    UltraEdit.activeDocument.write("dir \"C:\\Program Files\"");
    UltraEdit.activeDocument.selectToTop();
    UltraEdit.runTool("Any Console tool");
    // Evaluate the output when needed.
    UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
    UltraEdit.document[nActDocIndex].setActive();
    Macro template:

    Code: Select all

    NewFile
    UnicodeToASCII
    "dir "C:\Program Files""
    SelectToTop
    RunTool "Any Console tool"
    // Evaluate the output when needed.
    CloseFile NoSave
    It's up to you what the macro or script does before and after calling the tool.
    Best regards from an UC/UE/UES for Windows user from Austria

    7
    NewbieNewbie
    7

      Apr 16, 2010#2

      Mofi wrote:When you want to run any Windows application, and you want that your macro/script executing the application should wait until the Windows application terminates itself, configure a user tool as follows:

      On tab Command:

      Menu Item Name: Any Windows tool (for example)
      Command Line: start "UE Tool Execution" /wait %sel%
      Working Directory: (let it empty)
      Toolbar bitmap/icon: (let it empty or browse to a BMP or ICO file)
      Thanks!

      I ended up using the above quoted option, except I change the "Command Line:" option to:
      start "UE Tool Execution" %sel%

      This gave me the desired results, different from the other options given.