Questions tagged [shell-exec]

The shell_exec() PHP function provides the ability to run shell commands during the execution of a script.

The shell_exec() function provides the ability to run shell commands during the execution of a script. Other similar functions include, exec(), system(), passthru(), and the use of backticks around the command (``). It is important to note that commands executed this way will be run under the same permissions as the user that started the original process (i.e. calling this from a web page processed by Apache will run this under the same user Apache uses, typically httpd).

This functionality becomes handy when the developer wishes to execute a command which no API, library or extension for PHP exists. Example, a script you are developing needs to display the output of the UNIX vmstat command. PHP does not have visibility into such information, so the use of shell_exec('vmstat'); becomes warranted.

This function can be a security risk and, as such, this function is commonly disabled in shared hosting environments.

1065 questions
11
votes
7 answers

How to execute a php script from another php script by using the shell?

I have a php file called sample.php with the following content: And what I want to do, is to run this php script using a second php script. I think shell_exec could help me, but I don't know its syntax. By the way, I…
Sanjay Rathod
  • 1,083
  • 5
  • 18
  • 45
10
votes
1 answer

PHP shell_exec wait for script to finish?

I have a PHP script that queries a database for a list of jobs to be done and fires off other PHP scripts based on what it finds in the database (basically a process queue). Some of the scripts that the queue runner script executes may take 30…
Austin
  • 291
  • 1
  • 4
  • 12
10
votes
2 answers

Using PHP to execute cmd commands

How do I properly execute commands in the command line using php? For example I'm using the command below in the command line to convert a docx file into a pdf file: pdfcreator.exe /PF"D:\Documents\sample.docx Now using PHP code I want to be able…
Wern Ancheta
  • 22,397
  • 38
  • 100
  • 139
9
votes
6 answers

PHP sudo in shell_exec

I want to execute a command as root with shell_exec. Now I know this is dangerous, but believe me, you need to login with MOD_AUTH and have the right privilleges to come to this page. It's secure. How can I get this done?
www.data-blogger.com
  • 4,076
  • 7
  • 43
  • 65
8
votes
1 answer

PHP exec: hangs, doesn't continue to next line

I have a php file 'run.php' which I'm running from the terminal. Within this file I have the following lines: exec("open-crawlers $port 2>&1",$out,$code); echo 'hello'; The problem that I'm having is that the terminal hangs after executing the…
Fortisimo
  • 1,012
  • 2
  • 11
  • 26
8
votes
2 answers

How to execute a shell command from a php script

I would like to create a php script to execute a shell command and return its output. The server requires a private key. When I first decided to test this out I created this:
Kenneth Vogt
  • 985
  • 4
  • 12
  • 28
8
votes
4 answers

PHP running multiple scripts concurrently

I have an array with object server like this: Array ( [0]( ( [id] => 1 [version] => 1 [server_addr] => 192.168.5.210 [server_name] => server1 …
Lim SY
  • 175
  • 2
  • 15
8
votes
4 answers

Php check if shell_exec command was successful

I basically want to check if a command ran successfully using shell_exec. Simple function: public static function foo() { $command = "blabla"; shell_exec($command); } Edit, I tried Mister M's suggestion like this: foreach($commands as $key…
utdev
  • 3,942
  • 8
  • 40
  • 70
8
votes
5 answers

php libreoffice shell_exec not working

I am trying to convert .docx file to .html using php shell_exec in CentOS 6.5 My php code: $command = "libreoffice --headless -convert-to html resume.docx 2>&1"; $result = shell_exec($command); echo $result; When I run the index.php at…
Mohammed Sufian
  • 1,743
  • 6
  • 35
  • 62
8
votes
1 answer

shell_exec not running in background?

I have the following which executes perfectly but NOT in the background as it should? It actually stops the page loading until it finishes which is not good. shell_exec("/usr/bin/php /home/public_html/pages/test/backg.php {$user_info} {$user_info2}…
StudioTime
  • 22,603
  • 38
  • 120
  • 207
7
votes
5 answers

php shell_exec with realtime updating

I have this shell program that I want to execute by php. The problem is that it can potentially take a long time, and as of that I need it to have real-time updating to the user's browser. I read that I may need to use popen() to do that, but I am…
EduAlm
  • 813
  • 3
  • 11
  • 27
7
votes
3 answers

PHP -- Running shell_exec() does NOT return all output

I am using pdfgrep to search all appearances of a keyword in a PDF Document. Now, I want to do this via PHP so I can use this in my Web Site. However, when I run: $output = shell_exec("pdfgrep -i $keyword $file"); $var_dump($output); Where $keyword…
Razgriz
  • 7,179
  • 17
  • 78
  • 150
6
votes
3 answers

PHP shell_exec ssh connection

I know this question has been asked before in many different ways but I'm still scratching my head over why I can't get this to work. Firstly I have two SLES servers setup, these are Server A & Server B which are both running on a small private…
bikerben
  • 463
  • 5
  • 11
  • 18
6
votes
3 answers

C# equivalent to shell_exec

How execute command via shell and return the complete output as a string using C#? equivalent to shell_exec() of PHP. Thanks,advanced.
The Mask
  • 17,007
  • 37
  • 111
  • 185
6
votes
2 answers

Compiling C from PHP with exec error trying to exec 'cc1'

I am trying to compile a C program from PHP with exec, and with the Laravel Framework. But I dont think this is the problem, because I can compile and execute C programs from terminal without problems. And if you know from tinker in Laravel 5, so…
Marco Feregrino
  • 665
  • 5
  • 15
1
2
3
70 71