Sign in to follow this  

Execute shell command on MTA Server

Recommended Posts


Is possible to execute command on working server on windows? I mean I want to restart resource using batch without sending HTTP request on MTA Server.

Share this post

Link to post

Use callRemote or fetchRemote - the only way without creating your own server module (afaik)

Share this post

Link to post
2 hours ago, Piorun said:

I mean I want to restart resource using batch.

I don't want to use lua for this. I want to use batch script. Which means - 'if something happens inside my OS i want to restart server'.

Share this post

Link to post

You'll have to be more specific. You want to restart the MTA server when what happens?

Share this post

Link to post

For example: I will plug something to USB. From batch i can detect it and then i want to restart my resource. 

Share this post

Link to post

Doing it with Batch might be possible, but will be very ugly.

I suggest you use PowerShell or a scripting language (e.g. Python or Go) for that purpose. To do that, you've to redirect the standard input (stdin) so you can write input programmatically.

This is how it could be done with PowerShell:

# Set MTA server path
$mtaPath = "D:\\Program Files (x86)\\MTA San Andreas 1.5\\server";

# Prepare start options
$psi = New-Object System.Diagnostics.ProcessStartInfo;
$psi.WorkingDirectory = $mtaPath;
$psi.FileName = $mtaPath + "\\MTA Server.exe";
$psi.Arguments = "-n -t -u"
$psi.UseShellExecute = $false;
$psi.RedirectStandardInput = $true;

# Start process and wait 30s till it is fully up
$process = [System.Diagnostics.Process]::Start($psi);
Start-Sleep -s 30;

# Execute command

After the process has been started, you can write anything you want to the console (as long as it's done in the PowerShell script). If you want to attach to a running process, it'll get a little more complicated as you'd probably have to utilise IPC methods (for an example, see:

Alternatively, you could take a look at
This little Go app provides an HTTP-based API to control the MTA server (start/stop/inject commands). You could then use curl/PowerShell's Invoke-WebRequest to execute commands from a batch script. Let me know if you need more information on that.

  • Like 1

Share this post

Link to post

Sounds promising! I can't wait to test it. Thanks a lot! I will post updates in next hours.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.