0

I have a GUI with php, html, css, js and this site is on a local server.

I would like when I click on a button to open a cmd on the local server to open a cmd and launch a command.

I have already succeeded in doing it but the problem is that the command I want to use is sass --watch and as I said before the cmd does not launch.

I can already do an

$output = shell_exec('dir');
echo $output;

which is already good news, however, do

shell_exec('sass --watch ... ...')

do not work

  • In the title it says "on remote server", in the question it says "on local server". Make up your mind. Obviously though, PHP will launch the command on whichever machine it's being executed on, regardless of whether you've badged that as "local" or "remote" conceptually. – ADyson Nov 30 '22 at 09:28
  • `do not work`...doesn't work how, exactly? If you put that sass command into the same style as your first snippet, what output do you get? – ADyson Nov 30 '22 at 09:28
  • 2
    Why would you need to run `sass --watch` on a remote server to begin with? Are you doing _development_ on that machine? – CBroe Nov 30 '22 at 09:29
  • I think the command works but it does not stay open – William Gaonarch Nov 30 '22 at 09:32
  • What's your evidence for this? And what exactly did you expect to happen instead? Your description is quite vague. And please reply to my question...if you run your command `$output = shell_exec('sass....'); echo $output;`, what do you see as the output? What did you expect instead? – ADyson Nov 30 '22 at 09:33
  • when i echo this returns nothing – William Gaonarch Nov 30 '22 at 09:36
  • i expect the sass --watch start on my local server and stay on watch :) – William Gaonarch Nov 30 '22 at 09:37
  • I need to run sass --watch on my local server for don't use app like prepros – William Gaonarch Nov 30 '22 at 09:41
  • I suggest firing it in a separate command window maybe, using a technique like in the answer below. Then it can run a long-running process, and PHP doesn't have to wait for it to complete. – ADyson Nov 30 '22 at 09:42
  • allright so i do $output = shell_exec('start cmd.exe @cmd /k "sass --watch blabla blabla"'); and my browser loads endlessly – William Gaonarch Nov 30 '22 at 09:44
  • yes try that. https://stackoverflow.com/questions/7692263/running-a-php-exec-in-the-background-on-windows might also be relevant, possibly. Or https://stackoverflow.com/questions/2067900/php-on-a-windows-machine-start-process-in-background . Or [any of these](https://www.google.com/search?q=php+run+shell+command+in+background+windows) – ADyson Nov 30 '22 at 09:45
  • Ok I'll take a look and let you know if it works :) – William Gaonarch Nov 30 '22 at 09:47
  • ok suddenly I saw nothing works but a new track is actually starting shell_exec('start cmd.exe @cmd /k "sass --watch blabla blabla"'); I can see the cmd in the task manager of the local server But I think the sass --watch command does not launch and therefore remains looped on it There is no way to see the cmd in full screen? – William Gaonarch Nov 30 '22 at 10:50

1 Answers1

1

With the use of php you can do on Windows.

shell_exec('start cmd.exe @cmd /k "ping google.com"');
Gerhard
  • 22,678
  • 7
  • 27
  • 43
Piyush Sapariya
  • 408
  • 3
  • 11