Jump to content
  • 0

Execute shell command on MTA Server


Piorun

Question

6 answers to this question

Recommended Posts

  • 0

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
$process.StandardInput.WriteLine("help");

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: https://rkeithhill.wordpress.com/2014/11/01/windows-powershell-and-named-pipes/).

Alternatively, you could take a look at https://github.com/Jusonex/mtasa-deployment-tools/tree/master/Workerunit
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
Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...