lua io.popen运行程序,路径中有空格

时间:2018-11-23 20:52:30

标签: windows command-line lua

我正在尝试启动该程序,但我一直遇到错误。 我已经尝试过在字符串周围加上块引用[== [] ==],在程序路径周围使用“”,但是仍然无法使用。

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.

感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

在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窗口中从键盘键入命令时,这些附加引号会由处理键盘输入的代码自动添加。
当您使用Lua函数systemos.execute的C函数io.popen时,必须手动添加其他引号。
这就是CMD.EXE的工作方式(并且其设计充满了非常不逻辑的决定)。