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
6
votes
1 answer

php shell_exec permission denied

shell_exec("touch /Users/Nerses/Downloads/ads.txt 2>&1") I have a problem with the PHP exec(shel_exec) function. It says that I do not have permissions to execute the command. How can I open these permissions?
user3918128
  • 101
  • 1
  • 2
  • 9
6
votes
2 answers

Composer.phar don't want to run by shell_exec from PHP script. Why?

Trying to execute it with all possible params, such as -d and full path etc.. No errors. When running another commands, all is ok, when running composer from CMD, all is ok too. Have tried exec, system, shell_exec etc.. What it could be? echo…
andymcgregor
  • 1,005
  • 2
  • 13
  • 28
6
votes
1 answer

shell_exec with windows path not running

I am trying to run a command using shell_exec but its not returning any output. When I copy the command into command prompt it works like a charm. Here is the command I'm trying to run. $result = shell_exec('android update project -p…
Farhan Ahmad
  • 5,148
  • 6
  • 40
  • 69
6
votes
5 answers

PHP - Any chance to run GUI program through exec()?

i need to run a web browser (chrome - firefox ..) using exec i have tried to do it using bat file (this method mentioned here) C:\Users\farok\AppData\Local\Google\Chrome\Application\chrome.exe www.google.com when i open the file using windows every…
Farok Ojil
  • 664
  • 1
  • 12
  • 22
5
votes
2 answers

PHP detect if shell_exec() command failed

I'm running the ffmpeg command within PHP's shell_exec() to convert several videos in a list. Is there anyway to detect if an error happened while the video was being converted (or atleast verify it fully completed the conversion)? I don't want to…
floatleft
  • 6,243
  • 12
  • 43
  • 53
5
votes
4 answers

php system() shell_exec() hangs the browser

Possible Duplicate: Asynchronous shell exec in PHP i need to run a java program in the background. process.php contains shell_exec("php php_cli.php") php_cli.php contains shell_exec("java -jar BiForce.jar settings.ini > log.txt"); I am calling…
World
  • 2,007
  • 7
  • 27
  • 37
5
votes
3 answers

shell_exec not giving any result, and not doing anything

So I have question which in my head should seem very simple to solve. I want to ssh to a server, which I have done a ton of times, and then make a shell execute which I have done a ton of times as well, but it is not working. The code i am…
pkj
  • 109
  • 1
  • 9
5
votes
3 answers

How to ignore errors in shell_exec?

I get the output of a shell command in PHP as $str = shell_exec("command"); and run the PHP script in terminal. When the shell command returns an error, it will be printed on the terminal. How can I tell shell_exec to return the command output only…
Googlebot
  • 15,159
  • 44
  • 133
  • 229
5
votes
4 answers

Querying an audio/video file for information

I want a PHP function which receives the path to a file and returns an array of information about it. The PHP file can call FFmpeg. Returned data should be something like Array( [mime] => video/ogg [container] => Ogg [video]…
TRiG
  • 10,148
  • 7
  • 57
  • 107
5
votes
1 answer

PHP built-in web server running very slow

I'm a beginner in PHP and making a website that displays basic system information(CPU usage, memory usage etc)of a linux system on a webpage.For the web server, i used the built-in web server: php -S 192.168.1.36:8000 The frontend uses Bootstrap…
cgifox
  • 639
  • 11
  • 23
5
votes
3 answers

Cannot execute telnet commands using PHP shell_exec()

I am trying to do a mail verification using telnet and php. The whole process words fine in the terminal, but when I use php shell_exec(), it only runs upto the Telnet connection command. Once telnet is connected, the remaining telnet specific…
Parthapratim Neog
  • 4,352
  • 6
  • 43
  • 79
5
votes
1 answer

What is the best practice to run PHP script from PHP script?

I'd use the following code: $SERVER_PATH = dirname(__FILE__); shell_exec($PHP_LOCATION.' '.$SERVER_PATH."/script.php?k1=v1&k2=v2 > /dev/null 2>/dev/null &"); Where: $PHP_LOCATION should contain the path to PHP, $SERVER_PATH - is current working…
Vlada Katlinskaya
  • 991
  • 1
  • 10
  • 26
5
votes
1 answer

Running vcgencmd from php exec()

When I run vcgencmd measure_temp in the terminal, it gives the temperature reading of the cpu. But when i use the same command in php exec('vcgencmd measure_temp 2>&1') it gives following error in the browser: VCHI initialization failed How can…
Rkumar
  • 127
  • 2
  • 3
  • 10
5
votes
0 answers

How to run cmd commands as administrator from php

I am trying to learn the php shell_exec() function which I believe, enables us to run cmd commands from within a php script.But in my system, when I normally open the command prompt and type in a command, for example, ipconfig, it says : 'ipconfig'…
Arun Sivaraj
  • 333
  • 1
  • 3
  • 9
5
votes
6 answers

How to get shell_exec to run on IIS 6.0

The Problem I have a PHP script that uses shell_exec to run a pdf-to-text converter. To simplify the problem I've created a short script that uses shell_exec to just echo the output of the dir command.
Iain Fraser
  • 6,578
  • 8
  • 43
  • 68
1 2
3
70 71