Search code examples
emailluasendfreebsdenter

Force a (enter) in os.execute() in Lua


I want to force a enter in os.execute(). Im using Lua on FreeBSD and I want to write an email.

If I write this:

os.execute('mail -v -s \'Hello Im the Topic\' mail@hotmail.de')
os.execute('Hello this should be the message')
os.execute('.')

it doesnt work, I receive an email without any content, just the topic comes trough. Also, i get some errors in freebsd ('Hello this should be the message' is no command ... blabla)

So i want to force an (enter) in one os.execute. I tried:

os.execute('mail -v -s \'Hello Im the Topic\' mail@hotmail.de\nHello this should be a message\n.')

and

os.execute('mail -v -s \'Hello Im the Topic\' mail@hotmail.de\
Hello this should be a message\
.')

but both doesnt work.


Solution

  • Use io.popen to open a pipe to the command you want to execute and write to it the data you to send:

    local f=io.popen('mail -v -s \'Hello Im the Topic\' mail@hotmail.de','w')
    f:write[[
    Hello this should be a message
    .
    ]]
    f:close()