Execute a .bat file from a .lua script?

Discuss almost anything about RailWorks.

Execute a .bat file from a .lua script?

Unread postby mikeadams2k » Fri Feb 26, 2021 4:16 pm

I would like to be able to execute a .bat file from an engine script. Can anyone tell me if this is possible, and if so, give me an example of the code needed to make it work? I would appreciate it greatly! (I've searched the web and found a few examples, but haven't been able to make them work. Most of these examples say something like "I think this will work" or "you might try this". Nothing definitive.)
mikeadams2k
 
Posts: 195
Joined: Thu Mar 04, 2010 12:26 am
Location: Ocala, FL

Re: Execute a .bat file from a .lua script?

Unread postby bnsfsubdivision » Sat Feb 27, 2021 4:43 am

The code below will execute your batch file on Initialisation (i.e run it once and close it).

Code: Select all
function Initialise ()

    --EXECUTE ON INITALIZATION
    os.execute([["YOURDRIVE:\PATH\PATH\PATH\FILE.bat"]])

end
Kevin Schulz
Artist - Searchlight Simulations
User avatar
bnsfsubdivision
 
Posts: 822
Joined: Sun Feb 20, 2011 5:27 am

Re: Execute a .bat file from a .lua script?

Unread postby mikeadams2k » Sat Feb 27, 2021 8:59 am

Kevin, thank you very much!
mikeadams2k
 
Posts: 195
Joined: Thu Mar 04, 2010 12:26 am
Location: Ocala, FL


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests