Hey guys I have one php exec command that works on my remote linux server but not my windows (WAMP package) local server. I really want to create an identical workstation so I can test locally and then update my remote server. If anyone has any suggestions or solutions other than converting to linux, I would really appreciate it.
<?php
$safe_path = escapeshellarg('fake-virus.txt');
$command = '/usr/bin/clamscan --stdout ' . $safe_path;
$out = '';
$int = -1;
exec($command, $out, $int);
echo $int;
if ($int == 0) {
// all good;
} 开发者_开发知识库else {
echo 'o no';// VIRUS!;
}
?>
I really want to create an identical workstation so I can test locally and then update my remote server
Installing cygwin
is the wrong way to go about this. Just use virtualbox
, which you can get from here, and run an Ubuntu VM. Much easier (and nicer).
Use 'su' it works great for me when doing cool cross OS stuff
shell_exec('su Administrator -c "cmd/script"');
Its not that difficult to run cygwin with Apache PHP and more. Here is a pretty simple tutorial cygwin-apache-php Have fun!
At least in one instance I was able to use shell_exec() of php of wamp (on windows:-)) via cygwin. I had to install procps or something in the cygwin installer to have a top command of sorts in cygwin. Then I was able to use wamps php shell_exec to perform that cygwin top command using Kishans suggestion in http://php.net/manual/en/function.shell-exec.php:
<?php
echo $result = shell_exec("C:\cygwin64\bin\bash.exe --login -c '/cygdrive/c/cygwin64/bin/top.exe --b -n 1'");
?>
/////////////////
Kisha's remarks cited:
If you are on windows and has Cygwin, You can execute all your Cygwin binaries using shell_exec() as follows:
<?
$result = shell_exec("C:\cygwin\bin\bash.exe --login -c '/cygdrive/c/cygwin/bin/convert.exe --version'");
print($result);
?>
The key is the "--login" option which appends all the required common cygwin binary and library paths to $PATH. Without this option some of the cygwin binaries that links to other libraries ( Like ImageMagick binaries which links to X11 ) will not work and you may see errors like "cygX11-6.dll not found, Could not start convert.exe"
精彩评论