SOLVED
First of all, I tried this all on a Windows 10 machine, and I expect a blank page if I don't use echo. But the code doesn't work.
<?php
exec ('cmd.exe server.bat 2>&1', $output);
print_r($output);
?>
output:
Array ( [0] => Microsoft Windows [Version 10.0.17134.228] [1] => (c) 2018 Microsoft Corporation. All rights reserved. [2] => [3] => C:\wamp64\www\server> )
<?php
exec ("cmd.exe server.bat 2>&1", $output);
print_r($output);
?>
A subdirectory or file .exe already exists. Error occurred while processing: .exe. A subdirectory or file server.bat already exists. Error occurred while processing: server.bat.
This bat file is in the same directory as the PHP script.
@echo on
cd /
cd wamp64
cd www
cd minecraft-server-stuff
start java -Xms1024M -Xmx16G -jar server.jar
PHP itself is enabled in httpd-conf. I tried Apache as admin ( my Microsoft account name), this does change the executer to me. Safe_mode is not available as an option so I can't disable it( I assume that not available means not active), maybe because it was removed in PHP 5.4. Currently using PHP 7.something
I am using wampserver, which is using the .ini of php5.3.44 I tried setting the user in the httpd-conf as me, I have little coding experience so I don't know how to verify if that works. I tried setting Apache as my account, this appears to set Apache as my account.
I currently don't have access to the logs( not that it logs anything but actual code things, like syntax error and such) I also don't have access to any other code, due to the fact that I am on work.
how i got it to work. the bat file reads the contents of a txt file if the content matches the set string the code executes.
contents of the .bat file
@echo off
:b
:: delims is not import as token, a is input
set a=test
for /f "delims=" %%a in (your-txt-file-here.txt) do (
type nul >"your-txt-file-here.txt"
start java -Xms1024M -Xmx1G -jar forge-1.7.10-10.13.4.1614-1.7.10-universal.jar
)
::sleep voor 5 sec
PING -n 5 127.0.0.1>nul
goto b
contents of the .php file
<?php
$filename = 'your-txt-file-here.txt';
$somecontent = "test";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>