Run command in output pane by script?

226 views
Skip to first unread message

BugFix@AutoIt

unread,
May 30, 2013, 12:03:56 PM5/30/13
to scite-i...@googlegroups.com
When I write a command into console and press the ENTER key, the command is executed. (e.g. launches "calc" the Windows calculator).
Now i've tried to do the same, by insert the command by a script. But the attached CR(LF) will interpreted only as line break.

I've used the following Lua-script:


runCmdOnOutput('calc')

runCmdOnOutput = function(_sCmd)
output:ClearAll()
output:AddText(_sCmd .. '\n')

-- tested also with no result:
--~ output:AddText(_sCmd .. '\r')
--~ output:AddText(_sCmd .. '\r\n')
--~ output:AddText(_sCmd .. string.char(10))
--~ output:AddText(_sCmd .. string.char(13))
--~ output:AddText(_sCmd .. string.char(10)..string.char(13))
end


Is it possible to execute a command in this way in the console?

Best regards
BugFix

Neil Hodgson

unread,
May 30, 2013, 7:32:14 PM5/30/13
to scite-i...@googlegroups.com
BugFix@AutoIt:

> When I write a command into console and press the ENTER key, the command is executed. (e.g. launches "calc" the Windows calculator).
> Now i've tried to do the same, by insert the command by a script.

There is no access to SciTE's command execution system from scripts. The piece of code that runs commands entered into the output pane is looking for the user pressing Return.

Neil

Gavin Holt

unread,
Aug 5, 2015, 4:14:57 PM8/5/15
to scite-interest
Is there any hope of allowing scripts to run commands in the output pane?

I ask because I can't find any other way to pipe the output of Findstr (or similar) into the output pane, e.g.

function help_local_search() -- Searches a sibling directory for help text
    output:insert(-1,scite.GetProp("SciteDefaultHome").."\\tools\\search.bat "..
scite.GetProp("CurrentWord").." "..
scite.GetProp("CurrentSelection").." "..
scite.GetProp("FileDir").."\\..\\help\\*.*"
    -- Need to active with output:insert(Return)
end

Kind Regards

Gavin



Neil Hodgson

unread,
Aug 6, 2015, 12:43:14 AM8/6/15
to scite-i...@googlegroups.com
Gavin Holt:

> Is there any hope of allowing scripts to run commands in the output pane?

Yes, if someone wants to work on implementing that. There may be some complexities as it would be manipulating the commands queue inside a command.

Lua offers the os.execute function which you might be able to use.

Neil

Gavin Holt

unread,
Aug 6, 2015, 8:52:21 AM8/6/15
to scite-interest, nyama...@me.com
Many thanks for the info. 

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

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"])
    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


Reply all
Reply to author
Forward
0 new messages