0

I'm trying to open a Windows program from PHP using exec() on a local machine. Is it possible to start a system program (on Windows 10 if it's relevant) that runs in the foreground using PHPs exec function?

This line:

exec("C:/Windows/notepad.exe 2>&1");

Causes Microsoft's Notepad to open in the background (verified it is actually running using task manager) but I have no access to it, i.e., it doesn't open a window. How do I get it to run in the foreground so I can actually see it and interact with it?

George
  • 13
  • 4
  • 1
    Have a look here - https://stackoverflow.com/questions/1403203/php-how-do-i-start-an-external-program-running-having-trouble-with-system-and?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Blinkydamo Jun 01 '18 at 10:26
  • 1
    Possible duplicate of [php How do I start an external program running - Having trouble with system and exec](https://stackoverflow.com/questions/1403203/php-how-do-i-start-an-external-program-running-having-trouble-with-system-and) – Jeff Jun 01 '18 at 10:34
  • I've allowed WAMP to interact with desktop in Services but that doesn't change anything. It still runs as a background process. The process is also set to manual. – George Jun 01 '18 at 10:35

1 Answers1

0

So this seems like an utter ball ache to achieve using exec() for your average coder. There's another way to achieve this result: Have PHP generate .bat files using file_put_contents() with instructions to open a given file path and then auto-delete itself, like so:

@echo off
Start ""  "C:\Path\To\File\SomeFile.txt"
del %0

This method requires some kind of task scheduler to monitor a given folder and execute the batch files as they come in. I believe PowerShell can do this, and possibly the Windows Task Scheduler. I think Linux has Cron.

George
  • 13
  • 4