Page 1 of 1

running script in php

Posted: 2012-02-21T05:22:56-07:00
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

Re: running script in php

Posted: 2012-02-21T10:56:27-07:00
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.

Re: running script in php

Posted: 2012-02-21T11:43:34-07:00
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.

Re: running script in php

Posted: 2012-02-21T13:38:51-07:00
by Bonzo
I have posted in the xampp forum: Bash

Re: running script in php

Posted: 2012-02-22T01:04:42-07:00
by Bonzo
The jist of the reply on the xampp forum is no.

Re: running script in php

Posted: 2012-02-23T19:12:23-07:00
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!

Re: running script in php

Posted: 2012-02-29T03:06:06-07:00
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:

Re: running script in php

Posted: 2012-02-29T10:34:45-07:00
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?