【问题标题】:Force a (enter) in os.execute() in Lua在 Lua 的 os.execute() 中强制输入 (enter)
【发布时间】:2015-05-17 21:43:13
【问题描述】:

我想强制输入 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\
.')

但两者都不起作用。

【问题讨论】:

    标签: email lua send freebsd enter


    【解决方案1】:

    使用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()
    

    【讨论】:

    • 它对我来说很好用。什么不适合你?你得到一个 Lua 错误吗?尝试删除local
    • print("Started") local f=io.popen('mail -v -s \'Hello Im the Topic\' mail@hotmail.de','w') f:write[ [你好,这应该是一条消息。 ]] f:close() print("Executed") 它只显示“已启动”但未执行,没有错误
    • 什么都没有……只是再次“开始”。我也删除了本地
    猜你喜欢
    • 2010-09-13
    • 2011-08-27
    • 2012-03-29
    • 2012-12-13
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2014-02-11
    相关资源
    最近更新 更多