Piorun Posted August 30, 2017 Share Posted August 30, 2017 Hi, 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. Link to comment
0 Administrators Lpsd Posted August 30, 2017 Administrators Share Posted August 30, 2017 Use callRemote or fetchRemote - the only way without creating your own server module (afaik) Link to comment
0 Piorun Posted August 30, 2017 Author Share Posted August 30, 2017 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'. Link to comment
0 Administrators Lpsd Posted August 30, 2017 Administrators Share Posted August 30, 2017 You'll have to be more specific. You want to restart the MTA server when what happens? Link to comment
0 Piorun Posted August 30, 2017 Author Share Posted August 30, 2017 For example: I will plug something to USB. From batch i can detect it and then i want to restart my resource. Link to comment
0 Jusonex Posted August 30, 2017 Share Posted August 30, 2017 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. 1 Link to comment
0 Piorun Posted August 31, 2017 Author Share Posted August 31, 2017 Sounds promising! I can't wait to test it. Thanks a lot! I will post updates in next hours. Link to comment
Question
Piorun
Hi,
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.
Link to comment
6 answers to this question
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now