Execute .exe in PHP

2

I have an application which should run a .exe that starts the execution of a scanner . The executable I have in unit C but I can not find any way to execute it.

    
asked by Andres Galeano 10.01.2017 в 19:57
source

2 answers

0

Good morning guys and girls, solve it by creating an HTML protocol from the regedit link

I just pass the path of the executable and fixed!.

    
answered by 30.01.2017 / 16:45
source
2

You have several alternatives:

  • exec ("c: \ abc.exe", $ result);

    And then with a var_dump($resultado); you can see the result of your program, an element of the array per line sent to stdout.

  • passthru ("c: \ abc.exe", $ out);

    Here the function returns the exit code of the program in $out

  • Using pipes and proc_open ()

    Many times the output of the command line is not as "reliable" as one would like, if you do not return the output correctly you may have to consider using pipes to capture everything, this is a little more complicated.

    $proceso = proc_open('cmd', [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes); //abrimos el proceso cmd.exe proceso con 3 pipes, stdin, stdout y stderr if (is_resource($proceso)) { //si se ha creado el proceso... fwrite($pipes[0], '"C:\mis archivos\ejecutable.exe"'); //enviamos comando fclose($pipes[0]); //cerramos el pipe stdin... echo stream_get_contents($pipes[1]); //mostramos el output del pipe stdout fclose($pipes[1]); //cerramos el pipe stdout echo stream_get_contents($pipes[2]); //mostramos el output del pipe stderr fclose($pipes[1]); //cerramos el pipe stderr echo proc_close($proceso); //cerramos el proceso }

  • $ out = shell_exec ("c: \ abc.exe");

    Here you will have what is sent to stdout in $out

  • $ out = system ("c: \ abc.exe", $ code)

    Finally here you will have what stdout sends in $out and additionally the exit code of the program in $codigo

answered by 10.01.2017 в 20:04