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
5
votes
3 answers

Can't 'cd' with PHP shell_exec()

I'm trying to write a script to browse and return similar to working in the terminal. Most commands work fine, however cd /path/to/files just doesn't do anything.
Fluidbyte
  • 5,162
  • 9
  • 47
  • 76
5
votes
2 answers

How to set $PATH for php exec or shell_exec

I have set the PATH to run ant and it is working on putty but on php exec it is returning sh ant command not found i have tried to set PATH by export PATH=/usr/ant/bin
Anees v
  • 323
  • 5
  • 13
5
votes
1 answer

Browser Hangs Executing PHP that runs a Powershell

I am trying to run a simple PHP that runs a powershell script, if I use this code I get the results in a command window, but I get an empty array in the browser:
OmarL
  • 61
  • 4
5
votes
1 answer

Batch file that opens adobe reader to print PDF doesn't end/close

I have the following code in a batch file that is called by a PHP script using shell_exec(): "C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe" /t "D:\xampp\htdocs\instrument\app\webroot\Repair…
weedave
  • 237
  • 1
  • 7
  • 22
5
votes
3 answers

limit execution time of shell_exec

I have an exe file which has the following code: while(1) printf("hello\n"); I'm executing this exe through php using shell_exec $output = shell_exec('C:/Users/thekosmix/Desktop/hello.exe 2>&1'); echo $output; now the script is executing for very…
thekosmix
  • 1,705
  • 21
  • 35
4
votes
1 answer

How to execute multiple launch conditions on installer exit

I've managed to get WIX to launch my application on exit, but not sure how to schedule two custom actions using the WixShellExecTarget property. One CA is to launch an app and the other is a web page based on a url from another CA. These are both…
Jamie
  • 876
  • 1
  • 10
  • 28
4
votes
4 answers

shell_exec returns empty string

When I execute my command in PHP with shell_exec it always returns an empty string. I tried shell_exec('ls -l'); and it works. I put the command as a separate file and still same result. $shellOutput = shell_exec("pacmd list-sinks | grep 'volume:…
Risto Novik
  • 8,199
  • 9
  • 50
  • 66
4
votes
2 answers

Two Shell_Exec Command with PHP button but still in the One powershell?

I have Powershell syntax that can get data using ReadExisting(), but the problem is... that syntax must compele php condition before (and some shell_exec syntax when page load) I trying Get COM1 Data using powershell, and its working with this…
dooooooofai
  • 88
  • 1
  • 15
4
votes
1 answer

Setting environment variables inside PHP unit tests

I'm doing some basic unit testing on a utility function I made years ago but it involves accessing the $_SERVER array. Since my unit tests are run from the command line, I have to manually set the values of the array myself. This works well using…
dokgu
  • 4,957
  • 3
  • 39
  • 77
4
votes
1 answer

PHP shell_exec() doesn't work but commands work from console

I'm following this guide for deploying my website via Git, and I'm running into some problems with PHP shell_exec() or exec(). The deploy script runs several commands such as git, whoami, which git, rsync, etc. All of these commands work when I'm…
mcheah
  • 1,209
  • 11
  • 28
4
votes
2 answers

Can't use shell_exec for laravel artisan command in live server

I am using shell_exec command to run my artisan commands in the background. But when I run shell_exec in production server. The route code as follows Route::get('/test/exec', function () { echo shell_exec('php ../artisan migrate:status 2>&1;…
Tamizharasan
  • 293
  • 1
  • 5
  • 18
4
votes
2 answers

Is using shell commands from PHP/CGI bad practice?

Are shell commands considered a legitimate programming interface? Specifically, is there anything wrong with executing bash shell commands on a linux application server from PHP pages or CGI files? Does this introduce efficiency or security…
Yarin
  • 173,523
  • 149
  • 402
  • 512
4
votes
1 answer

Why does a long running Python script called from PHP fail

I have a Python script which converts a PDF file. It is called via PHP in my Laravel app: $command = escapeshellcmd("python /home/forge/default/pdf.py " . $id); $output = shell_exec($command); This works fine with any PDF up to 250MB, but fails…
samiles
  • 3,768
  • 12
  • 44
  • 71
4
votes
2 answers

shell_exec command in php not working properly

I am trying to execute a C program using the shell_exec command, which needs arguments to be passed. It is working for one input, but not working for others. I tried to run the C program through terminal, it is working for all the inputs. This is my…
4
votes
4 answers

How do I to properly handle spaces in PHP Shell_exec?

I'm running on win2003 server, PHP 526, via the cmd-line. I have a cmdline string: $cmd = ' "d:\Prog Files\foo.exe" -p "d:\data path\datadir" '; Trying to do this in php code $out = `$cmd`; # note use of backticks AKA shell_exec results…
Freddo411
  • 2,293
  • 3
  • 18
  • 17