在Lua中,强制在os.execute()中插入换行符(Enter)

我想在os.execute()中强制换行。我在FreeBSD上使用Lua并想写一封电子邮件。

如果我写这个:

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

它不起作用,我收到一封没有任何内容的电子邮件,只有主题。而且,在freebsd中我会收到一些错误('Hello this should be the message'不是命令... blabla)

所以我想在一个os.execute中强制换行。 我试过:

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

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

但两者都不起作用。

点赞
用户107090
用户107090

使用 io.popen 打开一个管道,以执行所需的命令并向其写入要发送的数据:

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()
2015-03-15 23:18:48