It is currently April 20th, 2024, 9:43 am

[SOLVED] How to execute app from lua? (.exe, etc)

Discuss the use of Lua in Script measures.
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

[SOLVED] How to execute app from lua? (.exe, etc)

Post by ~Faradey~ »

UPD: [SOLVED]

For example i want to execute an addon from lua, how to do this?
I've tried many methods and only one looks like working...

SKIN:BANG("E:\\Новая папка\\RainmeterUpdateChecker.exe") -not working
SKIN:BANG("!execute \[\"E:\\Новая папка\\RainmeterUpdateChecker.exe\"\]") -not working
but it would be nice to have it to work)
os.execute("E:\\Новая папка\\RainmeterUpdateChecker.exe")
only this seems to works but, only cmd window flashes and nothing appears :???:
I think it requires some dos command but i completely forgot these commands, or maybe i'm wrong and there is another way to do this?
Last edited by ~Faradey~ on December 20th, 2011, 6:22 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to execute app from lua? (.exe, etc)

Post by jsmorley »

This worked ok for me...

Code: Select all

PROPERTIES =
{

}

function Initialize()

end -- function Initialize

function Update()

	SKIN:Bang('!Execute [\"C:\\Program Files\\CCleaner\\CCleaner64.exe\"]')
	
	return 'I just ran CCleaner!'
   
end -- function Update
It is important to remember that Lua is ALWAYS case sensitive. There is no function "SKIN:BANG()" in our Lua implementation, only "SKIN:Bang()".

Notes:
  • The format SKIN:Bang('!Execute [\"C:/Program Files/CCleaner/CCleaner64.exe\"]') will also work, as Windows will accept either "\" or "/" as a path delimiter. Then you don't need to "escape" the "\" character. Probably best to stay in the habit of using standard and escaping path delimiters, but it is an option.

  • You are probably going to want to stay away from os.execute, as it can only send command to the "cmd.exe" interpreter, and although it works, and can even run Windows apps by using the "shell" cmd command, it will always pop up a cmd window.

  • Maybe (hopefully) not an issue, but Lua does not support Unicode characters very well, so if my approach doesn't work, try it with some path and program with only standard ANSI characters to be sure it isn't that...
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: How to execute app from lua? (.exe, etc)

Post by ~Faradey~ »

jsmorley wrote:It is important to remember that Lua is ALWAYS case sensitive. There is no function "SKIN:BANG()" in our Lua implementation, only "SKIN:Bang()".
yes :oops: this is my fault) i knew that it should work through SKIN:Bang
i didn't get used to lua yet and always forgetting about case-sensitive (that what happens when switching from one scripting language to another and vise versa in the same time...)
jsmorley wrote:You are probably going to want to stay away from os.execute, as it can only send command to the "cmd.exe" interpreter, and although it works, and can even run Windows apps by using the "shell" cmd command, it will always pop up a cmd window.
and this part is really annoying)
actually i've found another interesting function io.popen() while finding the answer on my issue but it is not important now, Thank you very much for your help, really it helped me a lot :thumbup:
I did some testing and noticed that lua works with Cyrillic as good as with Latin characters, as for putting path in cyrillic as it was needed (using ANSI), but if i need to use a unicode characters lua code is not working. I tried : Unicode (with and without BOM), UCS-2 (Big and Little Endian); none of them works. Good for me it supports cyrillic :)

Once again thanx :great: