Difference between revisions of "Os.execute"
From GiderosMobile
(added example from rrraptor) |
|||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | + | '''Available since:''' Gideros 2011.6<br/> | |
− | ''' | + | '''Class:''' [[Special:MyLanguage/os|os]]<br/> |
− | ''' | + | |
− | === | + | === 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. | |
<source lang="lua"> | <source lang="lua"> | ||
(number) = os.execute(command) | (number) = os.execute(command) | ||
</source> | </source> | ||
− | === | + | |
− | '''command''': (string) | + | === Parameters === |
− | === | + | '''command''': (string) command to execute <br/> |
− | ''' | + | |
+ | === Return values === | ||
+ | '''Returns''' (number) status code<br/> | ||
+ | |||
+ | === Example === | ||
+ | <source lang="lua"> | ||
+ | if application:getDeviceInfo() == "Windows" then | ||
+ | local lfs = require "lfs" | ||
+ | lfs.chdir(application:get("directory", "pictures")) | ||
+ | -- checks if "my_new_folder" directory exists | ||
+ | local islfsdir = lfs.chdir(lfs.currentdir().."\\".."my_new_folder") | ||
+ | if not islfsdir then | ||
+ | -- if not 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 the current lfs dir | ||
+ | os.execute("start "..lfs.currentdir()) | ||
+ | </source> | ||
{{Os}} | {{Os}} |
Revision as of 14:37, 26 December 2020
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
Example
if application:getDeviceInfo() == "Windows" then
local lfs = require "lfs"
lfs.chdir(application:get("directory", "pictures"))
-- checks if "my_new_folder" directory exists
local islfsdir = lfs.chdir(lfs.currentdir().."\\".."my_new_folder")
if not islfsdir then
-- if not 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 the current lfs dir
os.execute("start "..lfs.currentdir())