PowerShell run Ultraedit Script

441 Views Asked by At

Is it possible to run an UltraEdit macro or script from the PowerShell? Something like following:

uedit64.exe c:\temp\test.txt /s,e="c:\temp\script.js"

I have nothing special. I just want to open the log file with UltraEdit and as soon the log file is opened the UltraEdit Script should be executed on that. The following code opens the log file but does not execute the script on that.

$ultraEdit = "C:\...\UltraEdit\uedit64.exe"
$logFile = "C:\...\res.log"
$scriptFile = "C:\...\ultraEditScript.js"

Start-Process -FilePath $ultraEdit -ArgumentList "$logFile /s=`"$scriptFile`""
3

There are 3 best solutions below

0
Sherzad On BEST ANSWER

Thanks everyone, The problem was with Select-String that split the matched lines, therefore, the script did not perform any action due to improper file structure.

These two works great :-)

1. & $ultraEdit /fni $logFile /S=$scriptFile

2. Start-Process -FilePath $ultraEdit -ArgumentList "$logFile /S=$scriptFile"
1
Phillip Marshall On

Absolutely! Powershell has a few different "call" operators. https://ss64.com/ps/call.html

Take a look at the documentation for Start-process. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-6

Start-Process -FilePath "c:\pathtoexe\uedit64.exe" -ArgumentList "c:\temp\test.txt /s,e=`"c:\temp\script.js`""

Should work for you (change the path of course.

2
Maximilian Burszley On

Yes, it is possible. The problem with your current example is surrounding quoting rules with arguments:

uedit64.exe c:\temp\test.txt '/s,e="c:\temp\script.js"'

This form should work. When you use commas, will interpret that as an array. The safest way to pass arguments to an external executable is to use the stop-parser operator (--%) to avoid 's interpretation, but note this falls back to the parser on Windows:

#requires -Version 3
uedit64.exe --% C:\Temp\test.txt /s,e="C:\Temp\script.js"

What the difference in parsers means is that you can't expand variables (if you wanted $path\script.js) in the arguments after the stop-parser, but you can still utilize environment variables using the batch syntax %VAR%.

As a best-practice, it's recommended to fully-qualify your path and use the call operator for clarity:

& C:\Temp\uedit64.exe