shell-exec

php shell_exec with realtime updating

断了今生、忘了曾经 提交于 2019-11-27 18:34:26
问题 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 sort of (ok, I really am :P) a PHP noob and can't figure out how I may be able to do it. Would appreciate any help! 回答1: if( ($fp = popen("your command", "r")) ) { while( !feof($fp) ){ echo fread($fp, 1024); flush(); // you have to flush buffer }

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

試著忘記壹切 提交于 2019-11-27 17:34:54
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 preferred one when they can be equally used. For example, for unzipping a file or compressing a folder (with tar command), which one is preferred (probably from performance point of view)? UPDATE: In another question, I found a very useful link describing different aspects for these functions. I share the link here, as other may use to better understand

PHP - How to get Shell errors echoed out to screen

非 Y 不嫁゛ 提交于 2019-11-27 17:16:57
问题 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 /var/www/html/sitedomain/httpdocs/tmp/ebev1177.mp4")); However when I run the equivalent code in my terminal: > ffmpeg -i /var/www/html/sitedomain/httpdocs/tmp/ebev1177.mp4 I get back a whole load of useful information which ends in an error "At least one output

PHP sudo in shell_exec

断了今生、忘了曾经 提交于 2019-11-27 12:56:38
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? You could use the latest SVN version of phpseclib, a pure PHP SSH implementation , to do this. eg. <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); $ssh->login('username', 'password'); $ssh->read('[prompt]'); $ssh->write("sudo command\n"); $ssh->read('Password:'); $ssh->write("Password\n"); echo $ssh->read('[prompt]'); ?> The problem isn't that your page

Running shell script from java code and pass arguments

主宰稳场 提交于 2019-11-27 08:38:02
问题 I am executing a shell script from Java program. I have implemented it using Runtime class. Below is the code I implemented final StringBuilder sb = new StringBuilder("test.sh"); sb.append("/path to/my/text file"); final Process p = Runtime.getRuntime().exec(sb.toString()); Here sb is string buffer object where I append my parameters and use it in exec method. But the problem is the parameter I pass "/path to/my/text file" is considered as 4 parameters /path to /my/text file But if run in

Passing multiple PHP variables to shell_exec()?

主宰稳场 提交于 2019-11-27 04:14:48
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 argument: the /tmp/my_script.php When i change the call to: Code: $page = shell_exec('/tmp/my_script.php {$my_url} {$my_refer}'); It says it received 3 arguments but the argv[1] and argv[2] are empty. When i change the call to: Code: $page = shell_exec('/tmp/my_script.php "http://www.somesite.com/" "http://www.somesite.com/"'); The script finally

executing a Powershell script from php

痴心易碎 提交于 2019-11-27 02:17:30
问题 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 = "newEvent.ps1"; $runScript = $psDIR. $psScript; $runCMD = $psPath." ".$runScript." 2>&1"; echo "\$psPath $psPath <br>"; echo "\$psDIR $psDIR <br>"; echo "\$psScript $psScript <br>"; echo "\$runScript $runScript <br>"; echo "\$runCMD $runCMD <br>"; exec( $runCMD,

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

£可爱£侵袭症+ 提交于 2019-11-26 19:05:09
问题 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 preferred one when they can be equally used. For example, for unzipping a file or compressing a folder (with tar command), which one is preferred (probably from performance point of view)? UPDATE: In another question, I found a very useful link

Running python script in Laravel

风格不统一 提交于 2019-11-26 16:18:04
问题 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 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\query.png'; //queryImage $trainImage = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\2nd.png'; //trainImage $trainImage1 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\3rd.png';

PHP sudo in shell_exec

三世轮回 提交于 2019-11-26 16:10:01
问题 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? 回答1: You could use the latest SVN version of phpseclib, a pure PHP SSH implementation, to do this. eg. <?php include('Net/SSH2.php'); $ssh = new Net_SSH2('www.domain.tld'); $ssh->login('username', 'password'); $ssh->read('[prompt]'); $ssh->write("sudo command\n"); $ssh->read