Problem running a shell in php

1

I want to run a shell file from php using this command:

system('./12.sh');

And the content of that shell file is as follows:

  #!/bin/bash

source ~/.virtualenvs/cv/bin/activate

python /home/raul-pc/Documentos/codigo/rec_face.py

When I run the php program from the Terminal everything works fine using this command:

cam programa.php

But what I want is to be able to run it from the server. How can I achieve this?

    
asked by Leonardo Raul 04.05.2017 в 22:00
source

1 answer

1

PHP has a method to execute shell commands. It's called shell_exec :

  

Execute a command using the command interpreter and return the   full output as a string.

Syntax

string shell_exec ( string $cmd )

Parameters

cmd The command that will be executed.

Return values

The output of the executed command or NULL if an error occurs or the command produces no output.

Note: This function can return NULL when an error occurs or when the program does not produce any output. It is not possible to detect the execution failures using this function. exec () should be used when necessary to access the exit code of the program.

Ejemplo #1 Un ejemplo de shell_exec()

<?php
$salida = shell_exec('ls -lart');
echo "<pre>$salida</pre>";
?>
  

Note: This function is disabled when PHP is running in mode   sure.

DEMO

<?php

$salida = shell_exec('uname -a');
echo $salida;

?>

Result

Linux lvps83-169-3-96.dedicated.hosteurope.de 4.4.0-042stab120.16 
#1 SMP Tue Dec 13 20:58:28 MSK 2016 x86_64 x86_64 x86_64 GNU/Linux
    
answered by 05.05.2017 / 05:40
source