如何在 lua 脚本中执行批处理命令

如何使其工作。我正在尝试通过 lua 脚本运行批处理中的声音


batch = [[
@echo off
set "file=wuuf.wav"
(echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
  echo Sound.URL = "%file%"
  echo Sound.Controls.play
  echo do while Sound.currentmedia.duration = 0
  echo wscript.sleep 100
  echo loop
  echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs
]]

local p = io.popen([[cmd /c ]]..batch)

点赞
用户1847592
用户1847592
```lua
local script = [[
   Set Sound = CreateObject("WMPlayer.OCX.7")
   Sound.URL = Wscript.Arguments(0)
   Sound.Controls.play
   do while Sound.currentmedia.duration = 0
      wscript.sleep 100
   loop
   wscript.sleep Sound.currentmedia.duration*1000+100
]]
local f = io.open("sound.vbs", "w")
f:write(script)
f:close()

local file = "wuuf.wav"
os.execute('wscript sound.vbs "'..file..'"')
local script = [[
   Set Sound = CreateObject("WMPlayer.OCX.7")
   Sound.URL = Wscript.Arguments(0)
   Sound.Controls.play
   do while Sound.currentmedia.duration = 0
      wscript.sleep 100
   loop
   wscript.sleep Sound.currentmedia.duration*1000+100
]]
local f = io.open("sound.vbs", "w")
f:write(script)
f:close()

local file = "wuuf.wav"
os.execute('wscript sound.vbs "'..file..'"')
2020-10-28 13:21:58