【问题标题】:lua io.popen run program with space in pathlua io.popen 运行程序,路径中有空格
【发布时间】:2019-04-26 10:16:20
【问题描述】:

我正在尝试启动此程序,但我不断收到错误消息。 我已经尝试在字符串周围加上块引号 [==[]==] 并在程序路径周围加上 "" 但它仍然不起作用。

local test = string.format([==["C:\Program Files (x86)\Audacity\audacity.exe" "F:\Aufnahme %s.%s.%s\ZOOM0001.WAV"]==], tag, monat, jahr)

print(test)
io.popen(test)

error when running the lua file

If I copy the command from the print(test) and use that in cmd.exe it works.

感谢您的帮助:)

【问题讨论】:

    标签: windows command-line lua


    【解决方案1】:

    在 Windows 上,您必须将命令行(程序 + 参数)括在额外的外层引号中。

    local test = string.format([==["C:\Program Files (x86)\Audacity\audacity.exe" "F:\Aufnahme %s.%s.%s\ZOOM0001.WAV"]==], tag, monat, jahr)
    
    test = '"'..test..'"'
    print(test)
    io.popen(test)
    

    当您在 CMD.EXE 窗口中从键盘输入命令时,这些额外的引号将由处理您的键盘输入的代码自动添加。
    当您使用 C 函数 system 或 Lua 函数 os.executeio.popen 时,您必须手动添加额外的引号。
    这就是 CMD.EXE 的工作方式(它的设计充满了不太合乎逻辑的决定)。

    【讨论】:

      猜你喜欢
      • 2016-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 2019-12-25
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多