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
74
votes
6 answers

How To Execute SSH Commands Via PHP

I am looking to SSH out via PHP. What is the best/most secure way to go about this? I know I can do: shell_exec("SSH user@host.com mkdir /testing"); Anything better? That feels so 'naughty' :).
Justin
  • 42,716
  • 77
  • 201
  • 296
68
votes
1 answer

What are the differences of system(), exec() and shell_exec() in PHP?

It is possible to run an external command by three PHP functions of system(); exec(); shell_exec(); but what are their differences? In spite of their specific applications, in most cases, the can be equally used. I am curious to know which is…
Googlebot
  • 15,159
  • 44
  • 133
  • 229
62
votes
5 answers

Is there a list of 'if' switches anywhere?

Is there a list of all the if switches for use in Bash scripting? Sometimes I see someone using it and I wonder what the switch they're using actually does. An example is the -z in this one. I know how to use it, but I don't know where it was…
Danijel-James W
  • 1,356
  • 2
  • 17
  • 34
33
votes
1 answer

PHP - How to get Shell errors echoed out to screen

I am in the process of using shell_exec() for the first time. I am trying to convert some video files on my server using the ffmpeg shell script. When I the below code in the browser, it returns NULL: var_dump(shell_exec("ffmpeg -i…
Mazatec
  • 11,481
  • 23
  • 72
  • 108
23
votes
6 answers

Passing multiple PHP variables to shell_exec()?

I am calling test.sh from PHP using shell_exec method. $my_url="http://www.somesite.com/"; $my_refer="http://www.somesite.com/"; $page = shell_exec('/tmp/my_script.php $my_url $my_refer'); However, the command line script says it only received 1…
user2314387
  • 265
  • 2
  • 4
  • 10
22
votes
11 answers

Pinging an IP address using PHP and echoing the result

I have the following function that I doesn't work so far. I would like to ping an IP address and then to echo whether the IP is alive or not. function pingAddress($ip){ $pingresult = shell_exec("start /b ping $ip -n 1"); $dead = "Request…
Bernard
  • 1,209
  • 3
  • 17
  • 22
22
votes
3 answers

Running python script in Laravel

So, I am trying to run a python script in my Laravel 5.3. This function is inside my Controller. This simply passes data to my python script public function imageSearch(Request $request) { $queryImage =…
Carriane Lastimoso
  • 233
  • 1
  • 2
  • 7
19
votes
5 answers

Unable to execute child_process.exec() when path has spaces

I am using appjs * and I want to execute a command to open a folder. What I have var path = __dirname + '/folder to open/'; // path = C:\Program Files\myapplication/folder to open/ require("child_process").exec("start " + path); Error Could not…
Ron van der Heijden
  • 14,803
  • 7
  • 58
  • 82
16
votes
2 answers

'git pull' command work from terminal but not with php shell_exec() via git repository hook

I have create a webhook in my github repository which post on the hook url on my live server to run pull command for update my repo files on the server. The problem is the hook file which i have created is in the /var/www/site/web/hookfile.php (the…
Harish Kumar
  • 927
  • 3
  • 20
  • 46
16
votes
2 answers

PHP - How to know if server allows shell_exec

On some servers, PHP is not allowed to run shell commands via shell_exec. How can I detect if current server allows running shell commands via PHP or not? How can I enable shell commands execution via PHP?
arxoft
  • 1,385
  • 3
  • 17
  • 34
14
votes
7 answers

Connecting to Gmail IMAP PHP "Couldn't open stream"

There are lots of people having similar issues but no one is answering their questions. I have IMAP enabled in PHP, Using all the correct information. I don't see where I'm going wrong. Here's my code: $hostname =…
cream
  • 1,129
  • 5
  • 16
  • 26
12
votes
4 answers

executing a Powershell script from php

I'm trying to execute a powershell script from PHP, but it does not seem to work. The script 'newEvent.ps1' creates an event on the Exchange server. $psPath = "powershell.exe"; $psDIR = "C:\\wamp\\www\\ant\\assets\\ps\\"; $psScript =…
heshanh
  • 367
  • 3
  • 6
  • 19
12
votes
2 answers

Using wkhtmltopdf on Windows

I am trying to set up the nifty HTML to image plugin called wkhtmltopdf and I am having a really difficult time. What I did so far: Downloaded wkhtmltopdf zip package and upacked the file in my websites root folder As a test I included the…
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
12
votes
3 answers

CreateProcess and ShellExecute differences

What are the main differences between the two? I'm willing to run only another EXE from my (C++) application. Are there any differences when inheriting environments, security features etc?
Samuel
  • 2,430
  • 5
  • 31
  • 41
11
votes
4 answers

Shell_exec php with nohup

I think there are tons of similar posts but I haven't yet found a solution after searching around. Basically, I'm trying to run two scripts in the background. When I run them in the commandline, I see after calling my first script: /usr/bin/nohup…
Rio
  • 14,182
  • 21
  • 67
  • 107
1
2 3
70 71