Any way to call .exe as filter in Scite LUA?

192 views
Skip to first unread message

blue...@onepost.net

unread,
Nov 26, 2014, 4:28:02 PM11/26/14
to scite-i...@googlegroups.com
Is there some way that I've missed, or are there any plans to add the ability to, from a LUA function, execute an .exe, feeding a LUA string in as its STDIN, and capture its STDOUT back as a LUA string? Something like:

local sendToSTDIN = editor:GetSelText()
local reformattedResults = scite.Execute( "perl.exe myReformat.pl", sendToSTDIN )
print( reformattedResults )

I've been trying to fake this for years with LUA winapi.dll's "execute" function, along with temp files on a RAM disk (since it doesn't manage STDIN/STDOUT).

I also saw one example dynamically setting user commands and calling them from within LUA, but that seemed deprecated?

props["command.49.*"] = command
props["command.mode.49.*"] = "subsystem:shellexec"
-- trigger user command #49
scite.MenuCommand(1149)

Thanks in advance for any additional information. And if it's not available and not yet planned, might I suggest the immense usefulness of such a method <smile>?

Thanks!
--John


Philippe Lhoste

unread,
Nov 27, 2014, 8:51:59 AM11/27/14
to scite-i...@googlegroups.com
On 26/11/2014 22:28, blue...@onepost.net wrote:
> Is there some way that I've missed, or are there any plans to add the ability to, from a LUA function, execute an .exe, feeding a LUA string in as its STDIN, and capture its STDOUT back as a LUA string? Something like:
>
> local sendToSTDIN = editor:GetSelText()
> local reformattedResults = scite.Execute( "perl.exe myReformat.pl", sendToSTDIN )
> print( reformattedResults )
>
> I've been trying to fake this for years with LUA winapi.dll's "execute" function, along with temp files on a RAM disk (since it doesn't manage STDIN/STDOUT).
>
> I also saw one example dynamically setting user commands and calling them from within LUA, but that seemed deprecated?
>
> props["command.49.*"] = command
> props["command.mode.49.*"] = "subsystem:shellexec"
> -- trigger user command #49
> scite.MenuCommand(1149)
>

In pure Lua, from memory, people use popen to do that. Maybe it works in SciTE?

PS.: That's Lua, not LUA, it is not an acronym.

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

blue...@onepost.net

unread,
Nov 28, 2014, 9:43:19 PM11/28/14
to scite-i...@googlegroups.com
Thank you, Philippe. I'm hoping there's a way (or a planned feature) to do it more directly within SciTE; but if not, popen may be more direct than the execute-and-temp-files method I've been using. Some quick research looks like I might need to get the "ex" API and a simulated popen2 (for both stdin and stdout) working within Lua for Windows (and then within SciTE), though that seems to be hanging on the STDIN portion for me so far.

Neil Hodgson

unread,
Nov 28, 2014, 10:52:21 PM11/28/14
to scite-i...@googlegroups.com
bluelake:

> I'm hoping there's a way (or a planned feature)

There are currently no features planned for SciTE. New features normally occur when someone implements them and asks for the code to be integrated.

Neil

blue...@onepost.net

unread,
Nov 29, 2014, 10:17:32 AM11/29/14
to scite-i...@googlegroups.com, nyama...@me.com
Thanks, Neil. I'll experiment and see if there's a better way than I've been doing. If I wind up with anything that might be usefully incorporated into SciTE, I'll contact you.

And thanks as always for Scintilla and Scite!
--John

Gavin Holt

unread,
Aug 7, 2015, 12:47:21 PM8/7/15
to scite-interest, nyama...@me.com
Work around for windows:

I used the shell.dll (https://groups.google.com/forum/#!topic/scite-interest/bVeyCfZ3OIc) which has a nice shell.exec function, 
This has the appearance of piping the results to the output window. 

You can execute any string, in my example I am constructing this in the form of props[find.command]:

function help_local_search()
    if scite.GetProp("CurrentSelection") then
props["find.what"] = '"'..scite.GetProp("CurrentSelection")..'"'
    else
props["find.what"] = scite.GetProp("CurrentWord")
    end
    props["find.directory"] = scite.GetProp("SciteDefaultHome").."\\help"
    props["find.files"] = "*.txt"

    local success, output = shell.exec(props["find.command"], nil,true,true)
    print(">"..props["find.command"]) -- Just to mimic the normal echo of commands
    print(output)
end


I have pasted the help for shell.exec below for those who may be interested:

exec (strCommand, [strOperation], [boolNoShow], [bWaitOnReturn])

--Run external programm or open file with associate application. Allows to execute files, documents and links and to open folders in Windows Explorer.

Parameters:
strCommand  - filename or folder with possible startup parameters. Can contain %environments_variable%
strOperation  - executed operation from listed in the table:
boolNoShow  - true | false (default) - silent or show a window of the started program
bWaitOnReturn  - true | false (default) - boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script


Operation Description
open  Open. strCommand - filename or folder name (default)
edit  Edit. Opens a file for editing. strCommand should be the document.
print  Print. strCommand should be the document.
explore  ` Opens a folder in Explorer window (with two panels). strCommand - file or folder
select  Opens a folder in Explorer window and chooses the specified folder or a file. strCommand - file or folder
find  Showing a dialog box "File Search". strCommand should specify a folder path from which search will begin
properties Showing file|folder "Properties" window. strCommand - file or folder
other  Other operation available in context menu of a file. For example "Play" operation available for media files.


Return value:
  The first contains
    - at successful end: true or (if function has been started with parameter bWaitOnReturn = true), exit code of process
    - at failure: false
  The second value contains error/success message of operation;
  or contains the output text of the console application (if execute console applications with parameters boolNoShow = true and bWaitOnReturn = true)

Example:

-- run application
shell.exec("clipbrd.exe")
shell.exec("CMD /c IPCONFIG /all > out.txt", nil, true, false)

-- show result of console application
print( shell.exec("CMD /c DIR", nil, true, true) )
print( shell.exec("cscript /nologo %WINDIR%\\system32\\eventquery.vbs /?", nil, true, true) )

-- analysis of the exit code of process
if shell.exec("ping -n 1 localhost", nil, true, true) == 0 then
    print("Network works") else print("Network does not work")
end

-- open folder
shell.exec("%TEMP%")
shell.exec("%USERPROFILE%", "find")
shell.exec("%WINDIR%\\regedit.exe", "explore")
shell.exec("%ProgramFiles%", "properties")
shell.exec("%ComSpec%", "select")

-- open URL link
shell.exec("http://scite.net.ru/")

-- send e-mail
shell.exec("mailto:support"at"gmail.com")

-- open file (with associate application)
shell.exec("%WINDIR%\\WindowsUpdate.log")

-- print file
shell.exec("%WINDIR%\\win.ini", "print")

-- edit file
shell.exec("%WINDIR%\\winnt.bmp", "edit")

Kind Regards

Gavin

Pascal Guimier

unread,
Feb 23, 2016, 12:35:04 PM2/23/16
to scite-interest
Too bad, this is a windows only solution.
Trying to execute php debug each time the file is changed. Lua could have been the solution. But not under linux.
Scite-ru is windev only apparently (I tried to compile the sources, but I'm not skilled enough to go further).
Reply all
Reply to author
Forward
0 new messages