Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
os.execute(...) — Gideros Forum

os.execute(...)

MoKaLuxMoKaLux Member
edited April 26 in General questions
hope you are all doing fine :o
Is it possible to execute a cmd line to a program included in my gideros assets project?
For example I would like to run the fbx-conv.exe from code.
I included fbx-conv.exe at the root of the assets folder:

then I call:
	local initpath = self.modelpath or "c:/"
	local path = application:get("openFileDialog", "Choose|"..initpath.."|Fbx (*.fbx)") -- title|path|extensions
	if path ~= 0 then
		self:getFolderPathAndFileName(path)
		local fbx = self.finalfile
		local json = fbx:gsub(".fbx", ".json")
		os.execute("start fbx-conv.exe -f -v -o G3DJ ".."\""..self.finalfolder.."/"..fbx.."\"".." ".."\""..self.finalfolder.."/"..json.."\"")
	end
The problem is windows cannot find fbx-conv.exe.

When I run the code (print) directly from cmd this works fine.

My question is how to access fbx-conv.exe from my code?
I tried |R|fbx-conv.exe, assets\resource\fbx-conv.exe, ...

Thank you for your help :)
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Tagged:

Comments

  • MoKaLuxMoKaLux Member
    I kinda solved it :o
    First I need to ask the user the path to fbx-conv.exe
    then I use the path in os.execute:
    	local initpath0 = "c:/" local fbxconvpath = nil
    	local path0 = application:get("openFileDialog", "Choose|"..initpath0.."|Fbx Conv (*.exe)") -- title|path|extensions
    	if path0 ~= 0 then
    		print(path0)
    		fbxconvpath = path0
    	end
     
    	local initpath = self.modelpath or "c:/"
    	local path = application:get("openFileDialog", "Choose|"..initpath.."|Fbx (*.fbx)") -- title|path|extensions
    	if path ~= 0 then
    		self:getFolderPathAndFileName(path)
    		local fbx = self.finalfile
    		local json = fbx:gsub(".fbx", ".json")
    		os.execute("start "..fbxconvpath.." -f -v -o G3DJ ".."\""..self.finalfolder.."/"..fbx.."\"".." ".."\""..self.finalfolder.."/"..json.."\"")
    	end
    Now I need to store this path and reuse it :)

    Viva gideros!
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    Accepted Answer
    Assuming current work directory when your app is launched is the app root folder, I would have tried to run 'assets/fbx-conv.exe'. The thing is that os.execute() isn't aware of Gideros virtual folders such as |R|, |D| or |T|.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited April 26
    I think I tried that before, but I tried it again but file not found

    My solution (see previous post) is not too bad imho, I keep it this way until I do some more testing. Thanks for your answer :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • rrraptorrrraptor Member
    edited April 27 Accepted Answer
    If you REALLY want to run a program from project directory, you can use
    --go to addons example, and use "studio.lua" from there
    Studio.listFiles()
    Something like this:
    function executeFile(appName, params)
    	params = params or ""
    	if (application:isPlayerMode()) then 
    		local status, error = false, ""
    		if (not Studio) then 
    			status, error = pcall(require, "studio")
    		else
    			status = true
    		end
     
    		if (status) then 
    			local files = Studio.listFiles()
    			local path = ""
    			for i,v in ipairs(files) do 
    				if (v.name == appName) then 
    					path = v.source
    					break
    				end
    			end
    			assert(path ~= "", "Cant find \""..appName.."\"")
    			os.execute(("start %s %s"):format(path, params))
    		else
    			print(error)
    		end
    	else
    		local path = application:get("directory","executable")
    		path = path .. "/assets/resource/"..appName
    		os.execute(("start %s %s"):format(path, params))
    	end
    end
    -- usage:
    executeFile("MyExe.exe", "-f -v")
    Works for player mode and exported windows application (but if assets is NOT encoded).
    And remember to use addon player to make it work :D

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    Thank you rrraptor for your answer :) It is a bit complicated for my taste, I will use my answer in previous post for now.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.