os
The system operation module belongs to the built-in module. It can be called directly by the script scope without using import.
This module is also a native module of lua, and xmake has been extended to provide more practical interfaces.
editâš Only some readonly interfaces (for example:
os.getenv
,os.arch
) in the os module can be used in the description scope. Other interfaces can only be used in the script domain, for example:os.cp
,os.rm
etc.
os.addenv
bool os.addenv(string name[, string ...])
Add values to one environment variable
-- Add 'bin' to PATH
local ok = os.addenv("PATH", "bin")
When adding several values, they are concatenated depending on the current os.
-- MY_ENV=value1;value2 on windows,
-- MY_ENV=value1:value2 on linux
os.addenv("MY_ENV", "value1", "value2")
Introduced in version 2.1.5
See also
os.addenvp, os.addenvs, $(env), os.setenv, os.getenv, os.joinenvs
editos.addenvp
bool os.addenv(string key, table values, string separator)
Add values to one environment variable with a given separator
-- Add 'bin$lib' to PATH
local ok = os.addenvp("PATH", {"bin", "lib"}, '$')
Introduced in version 2.1.5
See also
editos.addenvs
table os.addenvs(table envs)
Add environment variables to current envs, return the all old envs
os.setenvs({EXAMPLE = "a/path"}) -- add a custom variable to see addenvs impact on it
local oldenvs = os.addenvs({EXAMPLE = "some/path/"})
print(os.getenvs()["EXAMPLE"]) --got some/path/;a/path
print(oldenvs["EXAMPLE"]) -- got a/path
Introduced in version 2.5.6
See also
editos.arch
string os.arch()
Get current system architecture
That is the default architecture of the current host system, for example, I execute xmake on linux x86_64
to build, then the return value is: x86_64
.
Introduced in version 2.0.1
See also
os.is_arch, is_arch, os.subarch
editos.args
string os.args(table aguments[, table opt])
Format arguments to be passed to a process
Valid fields for opt
are:
bool escape
, default value:false
bool nowrap
, default value:false
e.g:
local cmd = "program"
cmd = cmd .. " " .. os.args({"--value=hello, world", "-i", 123})
-- cmd is:
-- program "--value=hello, world" -i 123
Set escape
to true
if you want to escape backslashes:
print(os.args({"path=C:\\Folder\\Subfolder"})) -- got path=C:\Folder\Subfolder
print(os.args({"path=C:\\Folder\\Subfolder"}, {escape = true})) -- got path=C:\\Folder\\Subfolder
Set nowrap
to true
if you don't want to wrap quotes:
print(os.args({'path="C:/Program Files/xmake"', "-i", 42})) -- got "path=\"C:/Program Files/xmake\"" -i 42
print(os.args({'path="C:/Program Files/xmake"', "-i", 42}, {nowrap = true})) -- got path=\"C:/Program Files/xmake\" -i 42
See also
editos.argv
table os.argv(string command[, table opt])
Parse a command and split its arguments
Valid fields for opt
are:
bool splitonly
, default value:false
e.g:
local args = os.argv('cmd --value="hello, world" -i 123')
-- got {
-- "cmd",
-- "--value=hello, world",
-- "-i",
-- "123"
-- }
args = os.argv('cmd --value="hello, world" -i 123', {splitonly = true})
-- got {
-- "cmd",
-- '--value="hello, world"',
-- "-i",
-- "123"
-- }
See also
editos.atexit
nil os.atexit(function on_exit)
Register exit callback
e.g:
os.atexit(function (ok, errors)
print(ok, errors)
end)
See also
editos.cd
string os.cd(string dir)
Enter the specified directory
This operation is used for directory switching and also supports built-in variables, but does not support pattern matching and multi-directory processing, for example:
-- Enter the temporary directory
os.cd("$(tmpdir)")
If you want to leave the previous directory, there are several ways:
-- Enter the parent directory
os.cd("..")
-- Enter the previous directory, equivalent to: cd -
os.cd("-")
-- Save the previous directory before entering the directory,
-- then use it to cut back directly after the level
local oldir = os.cd("./src")
...
os.cd(oldir)
Introduced in version 2.0.1
See also
editos.cp
nil os.cp(string src, string dst[, table opt])
Copy files or directories
The behavior is similar to the cp
command in the shell, supporting path wildcard matching (using lua pattern matching), support for multi-file copying, and built-in variable support.
Valid fields for opt
are:
string rootdir
bool symlink
e.g:
os.cp("$(scriptdir)/*.h", "$(buildir)/inc")
os.cp("$(projectdir)/src/test/**.h", "$(buildir)/inc")
The above code will: all the header files in the current xmake.lua
directory, the header files in the project source test directory are all copied to the $(buildir)
output directory.
Among them $(scriptdir)
, $(projectdir)
These variables are built-in variables of xmake. For details, see the related documentation of built-in variables.
The matching patterns in *.h
and **.h
are similar to those in add_files, the former is a single-level directory matching, and the latter is a recursive multi-level directory matching.
This interface also supports `recursive replication' of directories, for example:
-- Recursively copy the current directory to a temporary directory
os.cp("$(curdir)/test/", "$(tmpdir)/test")
The copy at the top will expand and copy all files to the specified directory, and lose the source directory hierarchy. If you want to copy according to the directory structure that maintains it, you can set the rootdir parameter:
os.cp("src/**.h", "/tmp/", {rootdir="src"})
The above script can press the root directory of src
to copy all sub-files under src in the same directory structure.
âš Try to use the
os.cp
interface instead ofos.run("cp ..")
, which will ensure platform consistency and cross-platform build description.
Under 2.5.7, the parameter {symlink = true}
is added to keep the symbolic link when copying files.
os.cp("/xxx/foo", "/xxx/bar", {symlink = true})
Introduced in version 2.0.1
See also
os.trycp, os.vcp, os.mv, os.rm, os.ln, os.touch
editos.cpuinfo
table os.cpuinfo()
Get cpu information
print(os.cpuinfo())
-- got {
-- ncpu = 8,
-- usagerate = 0.0,
-- model_name = "Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz",
-- march = "Kaby Lake",
-- vendor = "GenuineIntel",
-- model = 158,
-- family = 6
-- }
print(os.cpuinfo("march")) -- got "Kaby Lake"
Introduced in version 2.1.5
See also
editos.curdir
string os.curdir()
Get the current directory path
Consistent with the result of $(curdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
Usage reference: os.tmpdir.
Introduced in version 2.0.1
See also
editos.date
table os.date(string format, numeric datetime)
See Date and Time.
See also
editos.default_njob
numeric os.default_njob()
Get default number of parallel jobs
print(os.default_njob()) -- got 10
Introduced in version 2.5.8
See also
editos.dirs
table os.dirs(string path_pattern[, function callback])
Traverse to get all the directories under the specified directory
Supports pattern matching in add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:
-- Recursive traversal to get all subdirectories
for _, dir in ipairs(os.dirs("$(buildir)/inc/**")) do
print(dir)
end
Introduced in version 2.0.1
See also
os.files, os.filedirs, os.isdir, os.match
editos.emptydir
bool os.emptydir(string path)
Check if the specified directory is empty
Returns true
is the directory is empty or doesn't exist. Returns false
otherwise.
os.exec
nil os.exec(string cmd_format[, ...])
Echo running native shell commands
Similar to the os.run interface, the only difference is that when this interface executes the shell program, it has the output printed in the console, which is used in general debugging. An exception will be raised if an error happens.
os.exec("program --%s=%d --path=$(buildir)", "value", 42)
Introduced in version 2.0.1
See also
os.run, os.runv, os.iorun, os.iorunv, os.execv, os.vexec, os.vexecv, os.isexec, vformat
editos.execv
bool, string os.execv(string cmd, table args[, table opt])
Echo running native shell commands with parameter list
Similar to os.exec, just the way to pass parameters is passed through the parameter list, not the string command, for example:
os.execv("echo", {"hello", "xmake!"})
In addition, this interface also supports an optional parameter for passing settings: redirect output, perform environment variable settings, for example:
os.execv("echo", {"hello", "xmake!"}, {stdout = outfile, stderr = errfile, envs = {PATH = "xxx;xx", CFLAGS = "xx"}})
Valid fields for opt
are:
bool try
, default value:false
string shell
table envs
table setenvs
table addenvs
filepath/file/pipe stdin
filepath/file/pipe stdout
filepath/file/pipe stderr
bool detatch
, default value:false
bool exclusive
, default value:false
Set try
to true
to return the errors instead of raising them.
local ok, errors = os.execv("echo", {"hello", "xmake!"}, {try = true})
Among them, the stdout and stderr parameters are used to pass redirected output and error output. You can directly pass in the file path or the file object opened by io.open.
After v2.5.1, we also support setting the stdin parameter to support redirecting input files.
!> stdout/stderr/stdin can simultaneously support three types of values: file path, file object, and pipe object.
In addition, if you want to temporarily set and rewrite some environment variables during this execution, you can pass the envs parameter. The environment variable settings inside will replace the existing settings, but will not affect the outer execution environment, only the current command.
We can also get all the current environment variables through the os.getenvs()
interface, and then pass in the envs parameter after rewriting some parts.
Introduced in version 2.1.5
See also
os.exec, os.run, os.vexec, os.vexecv, vformat
editos.exists
bool os.exists(string path)
Determine if a file or directory exists
Return false
if the file or directory does not exist
-- Judging the existence of the directory
if os.exists("$(buildir)") then
-- ...
end
-- Judging the existence of the file
if os.exists("$(buildir)/libxxx.a") then
-- ...
end
Introduced in version 2.0.1
See also
os.isfile, os.isdir, os.isexec
editos.exit
bool os.exists(string path)
Exit the program
Introduced in version 2.3.1
See also
editos.features
table os.features()
Get features
${print}(os.features())
-- got {
-- path_sep = "\",
-- path_envsep = ";"
-- }
Introduced in version 2.3.1
editos.filedirs
table os.filedirs(string path_pattern[, function callback])
Traverse to get all files and directories under the specified directory
Supports pattern matching in target.add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:
-- Recursive traversal to get all child files and directories
for _, filedir in ipairs(os.filedirs("$(buildir)/**")) do
print(filedir)
end
Introduced in version 2.0.1
See also
editos.files
table os.files(string path_pattern[, function callback])
Traverse to get all the files in the specified directory
Supports pattern matching in target.add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:
-- Non-recursive traversal to get all child files
for _, filepath in ipairs(os.files("$(buildir)/inc/*.h")) do
print(filepath)
end
Introduced in version 2.0.1
See also
os.isfile, os.dirs, os.filedirs, os.match
editos.filesize
numeric os.filesize(string path)
Get file size
print(os.filesize("/tmp/a"))
Introduced in version 2.1.9
editos.fscase
bool os.fscase([string path])
Test if the os has a case sensitive filesystem
Introduced in version 2.1.9
editos.getenv
string os.getenv(string envname)
Get system environment variables
print(os.getenv("PATH"))
Introduced in version 2.0.1
See also
os.getenvs, $(env), os.addenv, os.setenv
editos.getenvs
table os.getenvs()
Get all current environment variables
local envs = os.getenvs()
--- home directory (on linux)
print(envs["HOME"])
Introduced in version 2.2.6
See also
editos.getpid
numeric os.getpid()
Get the current process ID
Introduced in version 2.6.5
editos.getwinsize
table os.getwinsize()
Get the console window size
local winsize = os.getwinsize()
-- got {
-- width = 120,
-- height = 9001,
-- }
Introduced in version 2.1.4
editos.host
string os.host()
Get the operating system of the current host
Consistent with the result of $(host), for example, if I execute xmake on linux x86_64
to build, the return value is: linux
Introduced in version 2.0.1
See also
editos.iorun
string, string os.iorun(string cmd)
Quietly running native shell commands and getting output
Similar to the os.run interface, the only difference is that after executing the shell program, this interface will get the execution result of the shell program, which is equivalent to redirecting the output.
You can get the contents of stdout
, stderr
at the same time, for example:
local outdata, errdata = os.iorun("echo hello xmake!")
Introduced in version 2.0.1
See also
editos.iorunv
string, string os.iorunv(string cmd, table args[, table opt])
Run the native shell command quietly and get the output with a list of parameters
Similar to os.iorun, just the way to pass arguments is passed through the argument list, not the string command, for example:
local outdata, errdata = os.iorunv("echo", {"hello", "xmake!"})
local outdata, errdata = os.iorunv("echo", {"hello", "xmake!"}, {envs = {PATH="..."}})
Valid fields for opt
are:
string shell
table envs
table setenvs
table addenvs
filepath/file/pipe stdin
bool detatch
, default value:false
bool exclusive
, default value:false
Introduced in version 2.1.5
See also
editos.is_arch
bool os.is_arch(string arch[, string ...])
Test if a given arch is the current
local is_x86_64_or_arm64 = os.is_arch("x86_64", "arm64")
Introduced in version 2.3.1
See also
editos.is_host
bool os.is_host(string host[, string ...])
Test if a given host is the current
local is_windows_or_linux = os.is_host("windows", "linux")
Introduced in version 2.3.1
See also
editos.is_subarch
bool os.is_subarch(string subarch[, string ...])
Test if a given sub arch is the current
Introduced in version 2.3.1
See also
editos.is_subhost
bool os.is_subhost(string subhost[, string ...])
Test if a given sub host is the current
Introduced in version 2.3.1
See also
editos.isdir
bool os.isdir(string path)
Determine if it is a directory
Return false
if the directory does not exist
if os.isdir("src") then
-- ...
end
Introduced in version 2.3.1
See also
os.isfile, os.islink, os.isexec, os.exists
editos.isexec
bool os.isexec(string path)
Test if a file is executable
if os.isexec("path/to/file.exe") then
os.run("path/to/file.exe")
end
Introduced in version 2.0.1
See also
os.isfile, is.isdir, os.islink, os.exists
os.isfile
bool os.isfile(string path)
Determine if it is a file
Return false
if the file does not exist
if os.isfile("$(buildir)/libxxx.a") then
-- ...
end
Introduced in version 2.0.1
See also
os.isdir, os.islink, os.isexec, os.exists
editos.islink
bool os.islink(string path)
Determine if it is a link
Return false
if the link does not exist
if os.islink("/usr/lib/libmythings.so") then
-- ...
end
Introduced in version 2.0.1
See also
os.isdir, os.isfile, os.isexec, os.exists, os.ln
editos.isroot
bool os.isroot()
Test if xmake is running as root
Introduced in version 2.1.9
editos.joinenvs
table os.joinenvs(table envs, table oldenvs)
Join environment variables. Similar to os.addenvs but with two envs variable
local envs = {CUSTOM = "a/path"}
local envs2 = {CUSTOM = "some/path/"}
print(os.joinenvs(envs, envs2))
The result is: { CUSTOM = "a/path;some/path/" }
Introduced in version 2.5.6
See also
os.getenv, os.getenvs, os.addenv, os.addenvs
editos.ln
nil os.ln(string srcpath, string dstpath[, opt])
Create a symlink to a file or directory
-- creates a symlink file "xxx.txt.ln" which is pointing to "xxx.txt"
os.ln("xxx.txt", "xxx.txt.ln")
Valid field for opt
is:
bool force
, default value isfalse
Set force to true
if you wish to overwrite the item at dstpath
Introduced in version 2.2.2
See also
os.vln, os.islink, os.cp, os.mv, os.touch
editos.match
table, numeric os.match(string pattern[, mode[, function callback]])
match files or directories
The search pattern uses:
"*"
to match any part of a file or directory name"**"
to recurse into subdirectories
Valid values for mode
are:
'f'
ortrue
ornil
to only match files'd'
orfalse
to only match directories'a'
to match both files and directories
The function returns the items found and count.
local dirs, count = os.match("./src/*", true)
local files, count = os.match("./src/**.c")
local file = os.match("./src/test.c", 'f', function (filepath, isdir)
return true -- continue it
return false -- break it
end)
Introduced in version 2.0.1
editos.mclock
numeric os.mclock()
local time = os.mclock()
os.execv(program)
time = os.mclock() - time
print("time %0.3fs", time / 1000.)
See also
editos.meminfo
table os.meminfo()
local info = os.meminfo()
-- got {
-- availsize = 23124,
-- pagesize = 4096,
-- usagerate = 0.29091410873632,
-- totalsize = 32611
-- }
editos.mkdir
nil os.mkdir(string dir)
Create a directory
Support for batch creation and built-in variables, such as:
os.mkdir("$(tmpdir)/test", "$(buildir)/inc")
Introduced in version 2.0.1
See also
editos.mtime
numeric os.mtime(string path)
Get file modification time
local time = os.mtime("$(buildir)/file.o")
See also
editos.mv
nil os.mv(string src, string dst)
Move to rename a file or directory
Similar to the use of os.cp, it also supports multi-file move operations and pattern matching, for example:
-- Move multiple files to a temporary directory
os.mv("$(buildir)/test1", "$(tmpdir)")
-- File movement does not support bulk operations, which is file renaming
os.mv("$(buildir)/libtest.a", "$(buildir)/libdemo.a")
Introduced in version 2.0.1
See also
os.trymv, os.vmv, os.cp, os.trycp, os.rm, os.ln, os.touch
editos.nuldev
string os.nuldev([bool input])
Get the system null device
editos.pbcopy
nil os.pbcopy(string data)
Copy string data to pasteboard/clipboard
Currently only implemented for linux and macosx
See also
editos.pbpaste
string os.pbpaste()
Read string data from pasteboard/clipboard
Currently only implemented for linux and macosx
See also
editos.programdir
string os.programdir()
Get the xmake installation main program script directory
Consistent with the result of $(programdir), it is just a direct get returned to a variable, which can be maintained with subsequent strings.
Introduced in version 2.1.5
See also
editos.programfile
string os.programfile()
Get the path of the xmake executable
Introduced in version 2.1.5
See also
editos.projectdir
string os.projectdir()
Get the project home directory
Consistent with the result of $(projectdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
Introduced in version 2.1.5
See also
editos.projectfile
string os.projectfile()
Get the path to the current project xmake.lua file
See also
editos.raise
nil os.raise(string messageformat[, ...])
Raise an exception and abort the current script
-- Raise exception with message "the error #42 occurred"
os.raise("the error #%d occurred", errcode)
It is recommanded to use the builtin function raise
instead of os.raise
Introduced in version 2.2.8
See also
editos.readlink
Read the content of a symlink
os.touch("xxx.txt")
os.ln("xxx.txt", "xxx.txt.ln")
print(os.readlink("xxx.txt.ln")) -- got "xxx.txt"
Introduced in version 2.2.2
See also
editos.rm
nil os.rm(string path)
Delete files or directory trees
Support for recursive deletion of directories, bulk delete operations, and pattern matching and built-in variables, such as:
os.rm("$(buildir)/inc/**.h")
os.rm("$(buildir)/lib/")
Introduced in version 2.0.1
See also
os.tryrm, os.vrm, os.rmdir, os.mv, os.cp, os.touch
editos.rmdir
nil os.rmdir(string dir)
Delete only the directory
If it is not a directory, it cannot be deleted.
Returns true
on success, returns false, errmsg
otherwise.
Introduced in version 2.0.1
See also
editos.run
nil os.run(string cmd_format[, ...])
Quietly running native shell commands
Used to execute third-party shell commands, but will not echo the output, only after the error, highlight the error message.
This interface supports parameter formatting and built-in variables such as:
-- Formatted parameters passed in
os.run("echo hello %s!", "xmake")
-- List build directory files
os.run("ls -l $(buildir)")
Using this interface to execute shell commands can easily reduce the cross-platform build. For os.run("cp ..")
, try to use os.cp
instead.
If you must use this interface to run the shell program, please use the config.plat interface to determine the platform support.
For more advanced process operations and control, see the process module interface.
Introduced in version 2.0.1
See also
os.runv, os.vrun, os.iorun, os.exec, core.base.process
os.runv
nil os.runv(string cmd, table args[, table opt])
Quietly running native shell commands with parameter list
Similar to os.run, just the way to pass parameters is passed through the parameter list, not the string command, for example:
os.runv("echo", {"hello", "xmake!"})
Valid fields for opt
are:
string shell
table envs
table setenvs
table addenvs
filepath/file/pipe stdin
filepath/file/pipe stdout
filepath/file/pipe stderr
bool detatch
, default value:false
bool exclusive
, default value:false
Introduced in version 2.1.5
See also
os.run, os.vrunv, os.iorunv, os.execv
editos.scriptdir
string os.scriptdir()
Get the path of the current description script
Consistent with the result of $(scriptdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
Usage reference: os.tmpdir.
Introduced in version 2.0.1
See also
$(scriptdir), os.projectfile, os.projectdir
editos.setenv
bool os.setenv(string varname, string ...)
Set system environment variables
local ok = os.setenv("HOME", "/tmp/")
Introduced in version 2.0.1
See also
os.setenvp, os.setenvs, os.getenv, os.addenv
editos.setenvp
bool os.setenvp(string varname, table values, string separator)
Setting environment variables with a given separator
-- Set 'bin$lib' to PATH
local ok = os.setenvp("PATH", {"bin", "lib"}, '$')
Introduced in version 2.1.5
See also
editos.setenvs
table os.setenvs(table envs)
Set environment variables. Replace the current envs by a new one and return old envs
local envs = {}
envs["PATH"] = "/xxx:/yyy/foo"
local oldenvs = os.setenvs(envs)
-- ...
os.setenvs(oldenvs)
Introduced in version 2.2.6
See also
os.setenv, os.setenvp, os.getenvs
editos.shell
Get current shell (pwsh, cmd, ...)
print(os.shell())
-- got pwsh
Introduced in version 2.7.3
See also
editos.sleep
nil os.sleep(numeric interval)
interval
input value is in milliseconds.
os.sleep(1000)
See also
editos.strerror
string os.strerror()
Get the current internal error as a string
local errors = os.strerror()
-- got Unknown
See also
editos.subarch
string os.subarch()
Get Subsystem host architecture
print(os.subarch())
-- got x64
Introduced in version 2.3.1
See also
is_subarch, os.is_subarch, os.arch
editos.subhost
string os.subhost()
Get Subsystem host, e.g. msys, cygwin on windows
print(os.subhost())
-- got linux
Introduced in version 2.3.1
See also
os.is_subhost, is_subhost, os.host
editos.syserror
numeric os.syserror()
Get the current internal system error
Possible return values are:
os.SYSERR_UNKNOWN
(-1)os.SYSERR_NONE
(0)os.SYSERR_NOT_PERM
(1)os.SYSERR_NOT_FILEDIR
(2)os.SYSERR_NOT_ACCESS
(3)
local errcode = os.syserror()
-- got -1
See also
editos.term
string os.term()
Get current terminal (windows-terminal, vscode, ... )
print(os.term())
-- got xterm
Introduced in version 2.7.3
See also
editos.time
numeric os.time([table time])
See Date and Time.
See also
editos.tmpdir
string os.tmpdir([table opt])
Get temporary directory
Consistent with the result of $(tmpdir), it is just a direct return to return a variable that can be maintained with subsequent strings.
print(path.join(os.tmpdir(), "file.txt"))
Equivalent to:
print("$(tmpdir)/file.txt")
Valid field for opt
is:
bool ramdisk
, default value istrue
Introduced in version 2.0.1
See also
editos.tmpfile
string os.tmpfile(opt_or_key)
Get temporary file path
Used to get a temporary file path, just a path, the file needs to be created by itself.
local tmp1 = os.tmpfile("xxx")
local tmp2 = os.tmpfile({key = "xxx", ramdisk = false})
Valid fields for opt
are:
string key
bool ramdisk
, default value istrue
Introduced in version 2.0.1
See also
editos.touch
nil os.touch(string path[, table opt])
Create an empty file
print(os.isfile("xxx.txt")) -- got false
os.touch("xxx.txt")
print(os.isfile("xxx.txt")) -- got true
Valid field for opt
is:
numeric atime
, default value is0
numeric mtime
, default value is0
See also
editos.trycp
bool os.trycp(string srcpath, string dstpath[, table opt])
Try copying files or directories
Similar to os.cp, the only difference is that this interface operation will not throw an exception interrupt xmake, but the return value indicates whether the execution is successful.
if os.trycp("file", "dest/file") then
end
Valid fields for opt
are:
string rootdir
bool symlink
Introduced in version 2.1.6
See also
editos.trymv
bool os.trymv(string srcpath, dstpath)
Try moving a file or directory
Similar to os.mv, the only difference is that this interface operation will not throw an exception interrupt xmake, but the return value indicates whether the execution is successful.
if os.trymv("file", "dest/file") then
end
Introduced in version 2.1.6
See also
editos.tryrm
bool os.tryrm(string path[, table opt])
Try deleting files or directories
Similar to os.rm, the only difference is that this interface operation will not throw an exception interrupt xmake, but the return value indicates whether the execution is successful.
if os.tryrm("file") then
end
Valid field for opt
is:
bool emptydirs
, default value isfalse
Set emptydirs
to true
to also remove empty parent directories of this file path.
Introduced in version 2.1.6
See also
editos.vcp
nil os.vcp(string srcpath, string dstpath[, table opt])
Copy file or directory and echo the verbose info if [-v|--verbose] option is enabled
The interface is the same as os.cp.
See also
editos.vexec
nil os.vexec(string cmd_format[, ...])
Execute command and echo verbose info if [-v|--verbose] option is enabled
The interface is the same as os.exec.
See also
editos.vexecv
bool, string os.vexecv(string cmd, table args[, table opt])
Execute command with arguments list and echo verbose info if [-v|--verbose] option is enabled
The interface is the same as os.execv.
See also
editos.vln
nil os.vln(string srcpath, string dstpath[, opt])
Link file or directory and echo verbose info if [-v|--verbose] option is enabled
The interface is the same as os.ln.
See also
editos.vmv
nil os.vmv(string src, string dst)
Move file or directory and echo verbose info if [-v|--verbose] option is enabled
The interface is the same as os.mv.
See also
editos.vrm
nil os.rm(string path)
Remove file or directory and echo verbose info if [-v|--verbose] option is enabled
The interface is the same as os.rm.
See also
editos.vrun
nil os.vrun(string cmd_format[, ...])
Quietly run command and echo verbose info if [-v|--verbose] option is enabled
The interface is the same as os.run.
See also
editos.vrunv
nil os.runv(string cmd, table args[, table opt])
Quietly run command with arguments list and echo verbose info if [-v|--verbose] option is enabled
The interface is the same as os.runv.
See also
editos.workingdir
string os.workingdir()
Get the working directory
Introduced in version 2.1.9
See also
os.curdir, os.cd, os.projectdir
editos.xmakever
string os.xmakever()
Get the current xmake version
print(os.xmakever())
-- got 2.7.6
edit