lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

only when using paths from Lua. This case is invoking the os command processor, which expects the native directory separator, which happens to be a backslash on Windows.


Op 23 jun. 2014 16:48 schreef Robert Raschke <>:

It's best to use forward slashes in your file paths!

On Jun 23, 2014 1:40 PM, "Jerome Vuarand" <> wrote:
2014-06-23 7:19 GMT+01:00 Michael Gerbracht <>:
> I would like to use os.execute() to run an .exe file with a path as argument.
> I tried the following:
> path = [["C:\program files\lua\lua.exe" "C:\Users\name surname\test.lua"]]
> print(path)
> os.execute(path)
> I do get an error, that 'C:\Users\name' is not recogized as internal or
> external command.
> I know that you should put some quotes around the path if it contains spaces.
> And in my case both pathes used may contain spaces. If you put the content of
> path variable into a .bat file it works. I expected that os.execute(command)
> does the same as putting the command in a .bat file but there seems to be a
> difference.
> Do you have any idea how to get it working?

A good rule of thumb on Windows when you run a command through C
(which Lua uses) and the command contains double quotes, is to
surround the whole command with an additional pair of double quotes.
So your script should become:

path = [[""C:\program files\lua\lua.exe" "C:\Users\name surname\test.lua""]]

You can type "cmd /?" in a console for an explanation of what's going
on in details.