running script in php

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
raksha
Posts: 3
Joined: 2012-02-21T02:34:56-07:00
Authentication code: 8675308

running script in php

Post by raksha »

hello..

i am working on windows platform. i am successful running huemap script by installing cygwin.
now i want to run that script in php using exec command.
so my question is can the same huemap script run in php without cygwin?

i gone through viewtopic.php?f=4&t=9631.
so if yes, then
I am having xampp sever for php. I set the foll paths in script file:

# set directory for temporary files
dir="C:\xampp\tmp " # suggestions are dir="." or dir="/tmp"

# set directory for location of IM commands -- no trailing /
imdir="C:\xampp\cgi-bin" # suggestions imdir="/usr/local/bin" or imdir= "/usr/bin"

I have below file in C:\xampp\htdocs\phpashwini\script.php
script.php

Code: Select all

<?php

$cmd=" bash C:\xampp\cgi-bin hue.sh veg.png hueveg.png";
exec($cmd,$result);

if($result=="0")
echo "sucess";
else
echo"fail";


?>
and the script i.e hue.sh and my src img veg.png placed at C:/xampp/cgi-bin . the hue ,tolers parameter are defined in the hue.sh
this is i had done considering that without cygwin we can run script in php.. i don't get the output what i am doing wrong?

thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: running script in php

Post by fmw42 »

so my question is can the same huemap script run in php without cygwin?
I know you can run IM commands with PHP on windows without cygwin. But, I don't know PHP on Windows well enough to answer whether it can run IM/bash scripts without cygwin. I have my doubts.

Perhaps user Bonzo can provide the answer as he use PHP quite a lot. See http://www.rubblewebs.co.uk/index.php perhaps the answer is there.
Last edited by fmw42 on 2012-02-21T14:43:48-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: running script in php

Post by Bonzo »

I have not run a bash script on windows and assume the problem is Windows does not have the correct programs to support bash as well as the bash program.

Looking around I found win-bash but as it says in its description:
Remember: This is only the shell binary - it has same builtin commands, but for must purposes you would need additional un*x tools like ls, sed etc.
This question would probably be better posted on a xampp forum as there would be more members with experiance of the xampp capabilities.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: running script in php

Post by Bonzo »

I have posted in the xampp forum: Bash
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: running script in php

Post by Bonzo »

The jist of the reply on the xampp forum is no.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: running script in php

Post by anthony »

Bonzo wrote:Looking around I found win-bash but as it says in its description:
Remember: This is only the shell binary - it has same builtin commands, but for must purposes you would need additional un*x tools like ls, sed etc.
It just means that the shell is present and can parse and run available commands, (like IM "convert"). However for full UNIX shell processing (scripts) you may need other commands, like ls, cat, sed, awk, grep, find, xargs, etc.

Note thatmany things are built into the shell. cd, echo, printf, for, while; as well as things like creating shell functions, backgrounding processes, and file redirection are built-in.

So while you can not do an 'ls' your can do "echo *" to get a unformated directory listing, but then which has 'dir'.
Similarly you don't have 'cat' but windows does have its equivalent of 'type'.

I do have a shell script that can do a 'cat' and only use shell built-ins! This is the 'bash' version of a built-in cat.

Code: Select all

  shcat() {
    while test $# -ge 1; do
      while read -r; do
        printf "%s\n" "$REPLY"
      done < "$1"
      shift
    done
  }
This function makes no external command calls!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
raksha
Posts: 3
Joined: 2012-02-21T02:34:56-07:00
Authentication code: 8675308

Re: running script in php

Post by raksha »

thanks for viewing my problem..

i am able to run the huemap script in php without need of cygwin on xampp server
this is the code:

Code: Select all

<?php echo shell_exec("sh hue.sh -h 225,0 -t 50,0 earth.png yearth.png"); ?>
this may help others who wants running script in php. :wink:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: running script in php

Post by fmw42 »

Very interesting. But I wonder if you still have cygwin installed and it is using that somehow? What happens if you uninstall cygwin? Does it still work?
Post Reply