0

I run test.php on apache by xampp, exec() is not working, no error and no respond, test.py is not getting executed. please help , Thank you. I have

test.php

exec("C:\Users\Json\AppData\Local\Microsoft\WindowsApps\python.exe C:\xampp\htdocs\app\test.py 2>&1", $output);
print_r($output)

test.py

import os
os.system("start cmd /k")
8
  • 2
    Im not really sure whats the deal here, but your are starting an cmd (interactive shell) in your py script? What should it return, if it normaly opens an cmd window? Commented Nov 17, 2022 at 9:11
  • So you want a cmd window to appear? That's not so easy. See: stackoverflow.com/a/34526406 Commented Nov 17, 2022 at 9:12
  • @Foobar no error from the $output , test.py also not run yes i want to start cmd in py from php Commented Nov 17, 2022 at 9:15
  • @tobifasc even tho i try to create a txt file with open() in py , it also not working from php exec() Commented Nov 17, 2022 at 9:17
  • 2
    @JsonPrime I have looked a little bit around on stackoverflow and there are mayn questions on that topic. Maybe you should lookup some of them and may find your answer. Commented Nov 17, 2022 at 9:25

1 Answer 1

0

Backslashes will have to be escaped within the path.

So you will have to write it like this:

exec("C:\\Users\\Json\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe C:\\xampp\\htdocs\\app\\test.py 2>&1", $output);
print_r($output);
Sign up to request clarification or add additional context in comments.

14 Comments

Array ( [0] => The system cannot execute the specified program. )
That sounds like a different problem. Can you run the command within exec from the cmd?
with single slash it runs no error , also py was not running
It seems like something is wrong with your permissions / python installation. The code works fine for me with the exact paths you are using.
Ah, I see. I would assume your apache service doesn't have the correct permissions. You could try to configure the correct user or run it as admin. To do that just double click it in service.msc and there should be an option to login with a specific account. You could also open the path of the *.exe file and configure it to always run as admin.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.