Posted 21 February 2013 - 03:56 PM
Ok. So this topic is probably more for the desktop version of lua, but it could have some applications in computercraft for me as well.
So, from what I understand (Please correct me if I'm wrong), that in lua, when you're opening it from cmd, the standard output is the terminal window, and in the Lua Reference Manual, it says that I can change the output of the program to something else (e.g. a text file).
In case of errors this function raises the error, instead of returning an error code." What I tried to do in a program, is make it redirect the feedback from windows functions (using os.execute) to a throwaway file, then redirect to the standard output when done. However, when I tried it, it didn't really work. As in, it didn't change the output at all. Could someone please explain this to me?
Important Code:
So, from what I understand (Please correct me if I'm wrong), that in lua, when you're opening it from cmd, the standard output is the terminal window, and in the Lua Reference Manual, it says that I can change the output of the program to something else (e.g. a text file).
Spoiler
"When called with a file name, it opens the named file (in text mode), and sets its handle as the default output file. When called with a file handle, it simply sets this file handle as the default output file. When called without parameters, it returns the current default output file.In case of errors this function raises the error, instead of returning an error code."
Important Code:
Spoiler
print("Run notepad?")
local ans = io.read()
io.write("Filename?")
local filename = io.read()
local toThrow = filename..".h"
local toKeep = filename..".cpp"
io.output(io.tmpfile())
if string.lower(string.sub(ans,1,1)) == "y" then
os.execute("copy template.cpp "..toThrow)
os.execute("start notepad++ "..toThrow)
print("Press enter when done editing")
io.read()
end
io.write("You shouldn't see this?")
--Maybe here use another funtion to change output file, and see if it found/compiled file
os.execute("copy "..toThrow.." "..toKeep)
os.execute("del "..toThrow)
os.execute("c++ "..toKeep.." -o "..filename..".exe")
io.output(io.stdout)
print("Done")