Drew
Drew

Reputation: 710

Write to New File Created By Notepad In Lua

I'm aiming to open a new .txt file in Notepad and then write to it. Since the file I'm opening (notepad.exe) isn't the same file I want to write to (the new .txt file), I'm unaware of how I can write to the file. Here's the code I have so far:

    local list = io.popen("notepad.exe","w")
    print(list)
    list:write("Tester")
    list:flush()

Notepad is opened, but the text isn't written to the new file because the code is trying to edit notepad.exe instead.

What can I do to be able to edit the new opened .txt file? I don't want to actually save the file anywhere, so that's why I'm aiming to just put text in an untitled .txt file. Thanks in advance :)

Upvotes: 0

Views: 359

Answers (1)

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23767

Notepad does not respond console input.
You must find edit control on notepad's window and PostMessage keypressing event to it.

Or prepare temporary file and load it:

local list = io.open("newfile.txt","w")
list:write("Tester")
list:close()
os.execute("notepad.exe newfile.txt")

Upvotes: 2

Related Questions