* works at command prompt not as plugin

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

works at command prompt not as plugin

Post by Ron Melby »

Code: Select all

require("luacom")
local FSO = luacom.CreateObject("Scripting.FileSystemObject")
function rtv_canon_parts(_CFN)
	local _CFP = _CFN:match("(.*[/\\])")
	if _CFP == _CFN then
		error("no file provided.")
	end
	if FSO:FolderExists(_CFP) then
		local _fil = FSO:GetFileName(_CFN)
		local _ext = FSO:GetExtensionName(_CFN)
		local _xt = (".%s"):format(_ext)
		_fil = _fil:gsub(_xt, "")
		return _CFP, _fil, _ext
	end
	error("directory does not exist")
end

require("iuplua")
iup.SetGlobal("CUSTOMQUITMESSAGE", "YES")
iup.SetGlobal("UTF8MODE", "YES")
iup.SetGlobal("UTF8MODE_FILE", "YES")

WS_ENTER = true
WS_CANCEL = false
WS_Cancel = "Cancel"
WS_cancel = -1
WS_ERR = 2
WS_OK = "OK"
WS_ok = 0
WS_YES = "Yes"
WS_NO = "No"
WS_Ignore = "Ignore"
WS_Retry = "Retry"
WS_Abort = "Abort"

local objext = {
	asm = ".asm", -- assembled
	dsm = ".dsm", -- disassembled
	boc = ".boc", -- binary object code
	BOC = ".BOC", -- BINARY OBJECT CODE
	irp = ".irp", -- intermediate representation program
	rwc = ".rwc", -- refactor working code
}

-- exe
local exe = {
	["5.1"] = {
		epth = '"C:/Program Files (x86)/Lua/5.1/"',
		opth = "C:/Users/admin/Desktop/IRP/5.1/",
	},

	["5.3"] = {
		epth = '"C:/Program Files (x86)/Lua/5.3.6/"',
		opth = "C:/Users/admin/Desktop/IRP/5.3/",
	},
}

local src = ("%s/Plugins/*.fh_lua"):format(fhGetContextInfo("CI_APP_DATA_FOLDER"):gsub("\\", "/"))
local _dq = '"'
local epth
local opth

local pth
local fil
local ext

-- slt 5.1 5.3
function sltVER()
	local Opt = 0
	local WS_RC
	local txtOpt = {}

	WSTitle = "Version"
	txtOpt[0] = "5.1"
	txtOpt[1] = "5.3"

	WS_RC, Opt = iup.GetParam(WSTitle, nil, ("Table Type: %%o|%s|%s|\n"):format(txtOpt[0], txtOpt[1]), Opt)
	if not Opt then
		Opt = 0
	end

	_slt["_ver"] = { fn_key = WS_RC, ix = (Opt + 1) or 0, parm = txtOpt[Opt] or "" }
	return _slt["_ver"]
end -- fn sltVER

local _CFN, WS_rc = iup.GetFile(src)
if WS_rc == WS_cancel then
	return
end
if WS_rc == WS_ok then
	pth, fil, ext = rtv_canon_parts(_CFN)
	local _ver = sltVER()
	if _ver.fn_key == WS_CANCEL then
		return
	end
	epth = exe[_ver.parm].epth
	opth = exe[_ver.parm].opth
	opth = ("%s%s"):format(opth, fil)
end
local BOC = ("%sluac.exe -o %s%s%s%s %s%s%s"):format(epth, _dq, opth, objext["BOC"], _dq, _dq, _CFN, _dq)
local dsm = ("%sluac.exe -l -l > %s%s%s%s %s%s%s"):format(epth, _dq, opth, objext["dsm"], _dq, _dq, _CFN, _dq)

local b = os.execute(BOC)
local d = os.execute(dsm)

return


simple program really, the bottom line is the last 4 or 5 sentences. The problem is not in the code, unless its in the delivery to the OS.
I build a command in BOC and dsm I then execute it.

these are actual builds

BOC = "C:/Program Files (x86)/Lua/5.1/"luac.exe -o "C:/Users/admin/Desktop/IRP/5.1/Map Life Facts.BOC" "C:\ProgramData\Calico Pie\Family Historian\Plugins\Map Life Facts.fh_lua"
dsm = "C:/Program Files (x86)/Lua/5.1/"luac.exe -l -l > "C:/Users/admin/Desktop/IRP/5.1/Map Life Facts.dsm" "C:\ProgramData\Calico Pie\Family Historian\Plugins\Map Life Facts.fh_lua"

b and d wiil contain 1 nothing else to capture and the files are not build in the Desktop folder & etc

but if I copy the commands and paste them in a command prompt, the files appear and there are no warnings or errors ... is there an obvious problem here? is there a clever way to see why these are not working in the program but on the command prompt with some alternative coding?

Thanks.

Editing note: Ron submitted some amended code, which I've incorporated in this original post (with a bit of formatting to make it more readable).
FH V.6.2.7 Win 10 64 bit
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: works at command prompt not as plugin

Post by Ron Melby »

wondering about this, is there a way to elevate the command in lua? That could be the issue, as I am casting about wildly.
FH V.6.2.7 Win 10 64 bit
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: works at command prompt not as plugin

Post by tatewise »

Should "C:/Program Files (x86)/Lua/5.1/"luac.exe be "C:/Program Files (x86)/Lua/5.1/luac.exe"
i.e.
The 2nd string quote should be after luac.exe not before.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: works at command prompt not as plugin

Post by Ron Melby »

Mike, that iteration was tried, it didn't change anything.

however I now have placed the luac.exe inside epth table and removed it from the format.

situation is still the same, get 1 in return code and not created, in lua pgm, but if debugged and the exact statement is pasted in command prompt, it has no comment, warning, error, and the file is created in my desktop folder.
FH V.6.2.7 Win 10 64 bit
User avatar
Jane
Site Admin
Posts: 8507
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: works at command prompt not as plugin

Post by Jane »

You could try using the fhShellExecute instead, it has a few more options to trap for problems. It's most likely windows permissions problems and fhShellExecute might avoid the problem as it spins out a new process rather than trying to run Lua under fhlua.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: works at command prompt not as plugin

Post by tatewise »

I'm not sure if it is the problem, but have you read the Lua documentation for os.execute?
It returns three values, not just one.
i.e.
isOK, strText, intCode = os.execute(...)
where
isOK is either true or nil
strText is either "exit" or "signal"
intCode is a number giving exit or signal status

I wonder if the "operating system shell" used by os.execute(...) is the CMD prompt or the PowerShell?
Have you tried both with your 'working' command?

Might be worth giving FH API fhShellExecute(...) a whirl.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Ron Melby
Megastar
Posts: 917
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: works at command prompt not as plugin

Post by Ron Melby »

oh, this is plainly just pure evil.

require 'luacom'
local FSO = luacom.CreateObject('Scripting.FileSystemObject')
powershell
command prompt

they all handle the paths with spaces differently, where and how they are quoted.

it may be that luac.exe is sort of a one off, I am unsure at this point.
do any of you have fully formated paths (that contain spaces in directory sub-parts with commands that you execute in your plugins that you can provide me for more testing?

BOC = C:/"Program Files (x86)"/Lua/5.1/luac.exe -o "C:/Users/admin/Desktop/IRP/5.1/"##_asm.BOC C:/ProgramData/Calico Pie/Family Historian/Plugins/##_asm.fh_lua

dsm = C:/"Program Files (x86)"/Lua/5.1/luac.exe -l -l > "C:/Users/admin/Desktop/IRP/5.1/"##_asm.dsm C:/ProgramData/Calico Pie/Family Historian/Plugins/##_asm.fh_lua

this works in the program from above at the moment, but quoting rules do not seem to be consistent. for instance, luacom does not want to see quotes in the path, just the plain string.
FH V.6.2.7 Win 10 64 bit
Post Reply