1

I'm setting up a server running on windows 10 with WampServer64. It provides buttons on a web page to takes screenshots of the server screen and others actions with pyscreenshots and pyautogui (as shown below).

My python scripts works great in local with cmd but when I run them from the website they stop when the script encounter a pyscreenshot method or a pyautogui method like pyscreenshot.grab() I searched for problems between WampServer and python but I only saw things about CGI which is not my problem. I tried it anyway but it doesn't worked

Here is the logical scheme of my code :

<input type="button" value="Get Screenshot" onclick="GetScreenshot()" />
function GetScreenshot(){
    $.ajax({
        url:"handle_screenshots.php",
        type: "POST",
        data:{action:'start_screenshots'},
        success: function(result) {
            alert(result);
        }
    });
};
if ($_POST['action'] == 'start_screenshots') {
    $path = $_SESSION['path'];
    $duration = 1000;
    pclose(popen("start /B cmd /C py C:\\wamp64\\www\\RTS_WebApp\\python\\screenshot.py $duration \"$path\" >NUL 2>NUL", 'r'));
    echo "Screenshots started";
}
import pyscreenshot, datetime, time, sys, re, os

if __name__ == '__main__':
    duration = sys.argv[1]
    if ':' in duration:
        wordList = re.sub("[^\w]", " ", duration).split()
        if (len(wordList) == 3) :
            duration = int(wordList[0]) * 3600 + int(wordList[1]) * 60 + int(wordList[2])
    else:
        duration = int(duration)

    i = 1
    left = 140
    top = 70
    right = 900
    bottom = 550
    start_time = time.time()
    while duration > (time.time() - start_time):
        name = "img_{}.png".format(i)
        img = pyscreenshot.grab()
        img = img.crop((left, top, right, bottom))
        img = img.resize((img.size[0], img.size[1]))
        img.save("C:\\wamp64\\www\\RTS_WebApp\\static\\img\\current.png")
        i += 1

EDIT : I just tried with XAMPP and it does work, so I guess there is a problem between python and WAMP

JonOsterman
  • 123
  • 1
  • 3
  • 14

0 Answers0