Difference between revisions of "Os.execute"

From GiderosMobile
(→‎Examples: rrraptor)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[Special:MyLanguage/os|os]]<br/>
+
'''Class:''' [[os]]<br/>
  
 
=== Description ===
 
=== Description ===
Line 10: Line 10:
  
 
=== Parameters ===
 
=== Parameters ===
'''command''': (string) command to execute <br/>
+
'''command''': (string) command to execute<br/>
  
 
=== Return values ===
 
=== Return values ===

Revision as of 23:28, 28 October 2022

Available since: Gideros 2011.6
Class: os

Description

This function is equivalent to the C function system. It passes command to be executed by an operating system shell. It returns a status code which is system-dependent. If command is absent then it returns nonzero if a shell is available and zero otherwise.

(number) = os.execute(command)

Parameters

command: (string) command to execute

Return values

Returns (number) status code

Examples

Opens a folder (windows 10)

if application:getDeviceInfo() == "Windows" then
	local lfs = require "lfs"
	-- go to user/pictures folder
	lfs.chdir(application:get("directory", "pictures"))
	-- check if "my_new_folder" directory exists in user/pictures folder
	local islfsdir = lfs.chdir(lfs.currentdir().."\\".."my_new_folder")
	if not islfsdir then
		-- if doesn't exist then create it and go to it
		lfs.mkdir(lfs.currentdir().."\\".."my_new_folder")
		lfs.chdir(lfs.currentdir().."\\".."my_new_folder")
	end
end
-- opens a window of the current lfs dir
os.execute("start "..lfs.currentdir())

Or if your path contains spaces

local path = "H:\\ShdowPLAY\\TMP\\Mafia Definitive Edition"
--local path = "H:/ShdowPLAY/TMP/Mafia Definitive Edition" -- same
os.execute("start \"\" \"" .. path .. "\"")