I used following lua code to create some files and write some text append the the game.txt
function makeFiles()
os.execute( "mkdir season\\week1" )
newFile = io.open( "season\\week1\\game.txt", "a+" )
newFile:write('123')
newFile:close()
end
makeFiles()
The cmd told me something like: "season\week1" already exists (translated from German). I am searching for a way to disable the output from the CMD via lua. After running my script there shouldn't be a output in the CMD telling me messages, I need to run the code in a silent way, the user shouldn't see this. I ask because I need to deactivate outputs from cmd generally using lua.
That's not a lua question. If you want to silence the output from shell commands you silence the shell command.
The simplest way to do that for this specific instance is to use (assuming your system has it) the
-pargument tomkdirwhich silences the error on already existing directories.You could also (if
-pdoesn't exist for example) simply test for the directory firstos.execute("test -d season\\week1 || mkdir season\\week1").Finally, and more generally, if you don't want output from a command redirect the output to
/dev/null:os.execute("mkdir season\\week1 >/dev/null 2>&1").The above assumes a linux-like environment. I don't know if cmd.exe has similar redirection capabilities though I imagine it does. (
>nul 2>nulapparently according to YuHao's answer)