Page 1 of 1

how to run a external program?

Posted: Mon Apr 01, 2013 1:25 pm
by botje
like title, how do i run a cmdline program from the bot?

Re: how to run a external program?

Posted: Mon Apr 01, 2013 1:54 pm
by rock5
You can use system(cmd) or os.execute(cmd) like I did in my "login" script. http://www.solarstrike.net/phpBB3/viewt ... gin#p48107 You can check that out to see how I used os.execute to start the game client.

Re: how to run a external program?

Posted: Mon Apr 01, 2013 4:23 pm
by botje

Code: Select all

function MemClean(sleeptime)
	if sleeptime == nil or sleeptime == "" then sleeptime = 5000 end
	
	os.execute("start 'ramrush.exe' -AutoOptimize")
	yrest(sleeptime)
	os.execute("TASKKILL /IM ramrush.exe /F")
end
exe is in rombot folder, but cant find the program...

Re: how to run a external program?

Posted: Mon Apr 01, 2013 7:07 pm
by lisa
Notice in Rock's example he uses getExecutionPath().

Code: Select all

	client = string.lower(client)
	local path = getExecutionPath().."/"..client
	-- fix spaces
	path = string.gsub(path," ","\" \"")
	local a,b,c = os.execute("START "..path.." NoCheckVersion")
	if not a then
		error("Trouble executing shortcut. Values returned were: "..(a or "nil")..", "..(b or "nil")..", "..(c or "nil"))
	end
from rombot the getExecutionPath() is the rom folder, you can test from commandline.

Code: Select all

Command> print(getExecutionPath())
C:/micromacro/scripts/rom
if you add that print to your userfunction you can find out for sure where it is looking for the file to start.

Re: how to run a external program?

Posted: Tue Apr 02, 2013 8:18 am
by botje
thanx lisa, that did the trick ^^

Code: Select all

function MemClean(sleeptime)
	if sleeptime == nil or sleeptime == "" then sleeptime = 50000 end
	
	os.execute("start "..getExecutionPath().."/ramrush.exe -AutoOptimize")
	yrest(sleeptime)
	os.execute("TASKKILL /IM ramrush.exe /F")
end