在 Lua 中强制在 os.execute() 中输入 (enter)
Force a (enter) in os.execute() in Lua
我想在 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' is no command ... 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\
.')
但两者都不起作用。
使用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()
我想在 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' is no command ... 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\
.')
但两者都不起作用。
使用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()