Difference between revisions of "Os.execute"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
Line 5: Line 5:
 
=== Description ===
 
=== 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.
 
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">
+
<syntaxhighlight lang="lua">
 
(number) = os.execute(command)
 
(number) = os.execute(command)
 
</source>
 
</source>
Line 20: Line 20:
 
=== Examples ===
 
=== Examples ===
 
'''Opens a folder (windows 10)'''
 
'''Opens a folder (windows 10)'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
if application:getDeviceInfo() == "Windows" then
 
if application:getDeviceInfo() == "Windows" then
 
local lfs = require "lfs"
 
local lfs = require "lfs"
Line 38: Line 38:
  
 
'''Or if your path contains spaces'''
 
'''Or if your path contains spaces'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
local path = "H:\\ShdowPLAY\\TMP\\Mafia Definitive Edition"
 
local path = "H:\\ShdowPLAY\\TMP\\Mafia Definitive Edition"
 
--local path = "H:/ShdowPLAY/TMP/Mafia Definitive Edition" -- same
 
--local path = "H:/ShdowPLAY/TMP/Mafia Definitive Edition" -- same
Line 47: Line 47:
 
'''Copies some files from folder to folder beyond a given date'''
 
'''Copies some files from folder to folder beyond a given date'''
 
* see: '''https://learn.microsoft.com/en-gb/windows-server/administration/windows-commands/xcopy'''
 
* see: '''https://learn.microsoft.com/en-gb/windows-server/administration/windows-commands/xcopy'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
os.execute("xcopy \rawdata \reports /d:12-29-1993")
 
os.execute("xcopy \rawdata \reports /d:12-29-1993")
 
</source>
 
</source>
  
 
{{Os}}
 
{{Os}}

Revision as of 15:30, 13 July 2023

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. <syntaxhighlight lang="lua"> (number) = os.execute(command) </source>

Parameters

command: (string) command to execute

For Windows you can check:

Return values

Returns (number) status code

Examples

Opens a folder (windows 10) <syntaxhighlight lang="lua"> 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()) </source>

Or if your path contains spaces <syntaxhighlight lang="lua"> local path = "H:\\ShdowPLAY\\TMP\\Mafia Definitive Edition" --local path = "H:/ShdowPLAY/TMP/Mafia Definitive Edition" -- same os.execute("start \"\" \"" .. path .. "\"") </source>


Copies some files from folder to folder beyond a given date

<syntaxhighlight lang="lua"> os.execute("xcopy \rawdata \reports /d:12-29-1993") </source>