I installed the software imagemagick on my server "Windows Server 2008".
In cmd it works fine, all commands work.
But when I try to do it in PHP:
$command = "convert fdfdf.jpeg dfdf2.jpeg";
exec($command, $output);
It does not work. I get a blank page and nothing happens,
I have given all the permissions I need to the following:
cmd.exe
whomi.exe
c:\ImageMagick. execute & read to iis_iusrs and everyone.
Safe Mode are off.
What else can I do to make it work?
Try this
$command = "convert fdfdf.jpeg dfdf2.jpeg 2>&1";
exec($command, $output);
var_dump($output);
Related
On windows xp I can run many commands form PHP with shell_exec() function.
I need to use OfficeToPDF on windows 10 with PHP.
My php script is:
<?php
$command = 'OfficeToPDF input.docx output.pdf';
$exec = shell_exec($command);
echo $exec;
?>
This script works on windows XP Professional, but not on windows 7, 8, 10.
OfficeToPdf simply opens Microsoft Word and saves file as PDF.
What changed on win7, win8, win10? Why I couldn't execute this command from PHP on new OS's?
I have apache service automaticly starts from SYSTEM user.
UPDATE: But I can run OfficeToPDF input.docx output.pdf command when I open cmd window manually.
I suspect that some environment variables are missing that are required. You should try running from within a command window instance, that will setup the default env vars:
$command = 'cmd /c OfficeToPDF input.docx output.pdf';
$exec = shell_exec($command);
echo $exec;
You might want to use the full path to OfficeToPDF, input.docx and output.pdf in case your default directory is incorrect, or call chdir() first.
The meaning of /C is:
/C Carries out the command specified by string and then terminates
i have a website that allows users to upload videos and I have VPS server with ffmpeg installed, safe mode is off and have tested command in my terminal and it works however in php script when i try and run the command in exec() or even shell_exec() it does not execute. below is my code (changed some variables for privacy).
$video_name = $_FILES["post_vid"]["name"];
$Vurl = "/folder1/folder2/$vrand_file_name/$video_name";
$VnewName = $vrand_vid_name .".mp4";
$VurlNew = "/folder1/folder2/$vrand_file_name/$VnewName";
$convertold = "/home/user/directory/domain.com/$Vurl";
$convertNew = "/home/user/directory/domain.com/$VurlNew" ;
$ffmpegC = "/user/local/bin/ffmpeg";
exec($ffmpegC.' -y -i "'.$convertold.'" -f mp4 "'.$convertNew.'"');
I have the code just after a move_uploaded_file() which runs fine.
also checked and my php is using the same user as my terminal...
any insight to this would be fantastic, thanks in advance.
Please fix your code near exec as follows, and Could you try?
$command = $ffmpegC.' -y -i "'.$convertold.'" -f mp4 "'.$convertNew.'" 2>&1';
exec($command, $array);
var_dump($array);
exit;
By using 2>&1, stderror is entered to $array.
So you can see the cause.
Good luck!
I tried many solutions but nothing it works :
echo '<pre>';
shell_exec("python /home/folder/python/mapfile_compress.py");
shell_exec("sudo -u wwwexec python escapeshellcommand(/home/folder/python/mapfile_compress.py) $uid");
shell_exec("sudo chmod +x /home/folder/python/mapfile_compress.py");
system("bash /home/folder/python/mapfile_compress.py");
passthru("bash /home/folder/python/mapfile_compress.py");
passthru("/home/folder/python/mapfile_compress.py");
exec("bash /home/folder/python/mapfile_compress.py");
echo '</pre>';
I launched indivdually them but in all cases, Firebug returned : '<pre>'
So I tried this code founded on Stack Overflow :
$command = escapeshellcmd('chmod +x /home/folder/python/mapfile_compress_test.py');
echo $command;
$output = shell_exec($command);
echo $output;
But firebug returned nothing.
My python file begin with #!/usr/bin/env python and if I launch it on server that works !
Do you knwo how can I launch my python file from PHP file ?
chmod will return 0 on success and > 0 on error.
Make sure that the file is able to run by just executing it as the web user. When +x is properly set, you can execute it by just calling $ /path/to/your/file.py, the shebang in the first line in your script #!/usr/bin/env python should define the correct python based on your env.
You can test this by running:
$ /usr/bin/env python /path/to/your/file.py
So check your file permissions to check if the file is executable by the user that runs the php script.
Just to test, you can just print a few lines in your python file
#!/usr/bin/env python
print "test line 1"
print "test line 2"
Then if you have verified permissions and the correct use of python, you can do this in your php.
$command = escapeshellcmd('/path/to/your/file.py');
$output = shell_exec($command); // get all output or use passthrough, exec will only return the last line.
echo "<pre>{$output}</pre>;
At first, Do you have enabled shell_exec/system/passthru commands in php.ini?
shell_exec("python /home/folder/python/mapfile_compress.py");
I think, it could be problem with your $PATH. Try something like: (use full path to python)
shell_exec("/usr/bin/python /home/folder/python/mapfile_compress.py");
shell_exec("/usr/local/bin/python /home/folder/python/mapfile_compress.py");
In my case that's work if I write this code :
$command = escapeshellcmd('python /path/to/your/file.py');
exec($command);
I'm trying to run ffmpeg through a PHP exec call, I've been debugging for a while and looked at lot of responses on here, but still not found any answers...
My simplified call is:
$cmd = 'ffmpeg 2>&1';
exec(escapeshellcmd($cmd), $stdout, $stderr);
var_dump($stderr);
var_dump($stdout);
var_dump($cmd);
exit;
My output is $stderr = int(1) and $stdout = array(0) { }
Also I tried shell_exec($cmd) which returns NULL.
cmd.exe has permissions set for the IUSR account - e.g. I can run $cmd = 'dir' and see a directory listing output.
PHP is not running in safe mode.
The ffmpeg.exe is in the same directory as my php file, but I have the same response giving an absolute path to the ffmpeg.exe file in $cmd.
ffmpeg is executing fine from the command line.
I'm running Windows XP, IIS and PHP 5.3.
EDIT:
If I run 'ffmpeg -h' I get the help commands, which must indicated that ffmpeg is recognised
I've increased the PHP memory limit to 1024 - no luck.
I've now got this working - I think there may have been several issues:
It turns out that $cmd = 'ffmpeg' returns null, so it's not a good test!
Also running escape shell command on '2>&1' echoes 2^>^&1" - I think this was my original problem.
I've now managed to rea test file using: 'ffmpeg -i SAMPLE.AVI 2>&1'.
Working code:
$cmd = 'ffmpeg -i SAMPLE.AVI 2>&1';
exec($cmd, $output, $value);
var_dump($output);
var_dump($value);
var_dump($cmd);
exit;
As noted above ffmpeg is a bit of a memory hog, so it's worth checking memory too.
Here is my php code
$command = "C:\Program Files\ClustalW2>clustalw2 -INFILE=seq.txt -TYPE=Protein -OUTFILE=res.aln";
exec($command);
When i run the command using the cmd, it generates the desired file. However when i try passing the same command via my php code it generates no result. How do i fix this problem?
Probably it's because of the > symbol before executable's filename? Also, try with single quotes:
$command = 'C:\Program Files\ClustalW2\clustalw2 -INFILE=seq.txt -TYPE=Protein -OUTFILE=res.aln';
exec($command, $output, $retval);
var_dump($output);
var_dump($retval);