ElectricShaka Posted March 14, 2008 Share Posted March 14, 2008 I have a spare computer with xampplite installed. I'm using this computer as a server. I have a program installed on this server computer which I'm trying to run with the exec function in a php page. This is my first time using exec() so I'm sure I have something wrong with my code because the program does not run at all. If anyone could offer me some advice I'd greatly appreciate it. exec(webshotcmd.exe /url "http://www.myurl.com/preview.php?prev=$title" /out "images/$name" /width "300" /height "240" /bwidth "768" /bheight "1024"); Quote Link to comment Share on other sites More sharing options...
Guest Posted March 14, 2008 Share Posted March 14, 2008 You need to put the command in quotations. The proper syntax is as follows: exec ( string $command [, array &$output [, int &$return_var ]] ) (http://ca3.php.net/function.exec) exec('webshotcmd.exe /url "http://www.myurl.com/preview.php?prev=$title" /out "images/$name" /width "300" /height "240" /bwidth "768" /bheight "1024"') EDIT: Sorry, i didn't see the variable inside (corrected): exec('webshotcmd.exe /url "http://www.myurl.com/preview.php?prev='.$title.'" /out "images/$name" /width "300" /height "240" /bwidth "768" /bheight "1024"') Quote Link to comment Share on other sites More sharing options...
ElectricShaka Posted March 14, 2008 Author Share Posted March 14, 2008 Thanks 8ball, Now I'm getting Parse error: syntax error, unexpected T_VARIABLE in C:\xampplite\htdocs\takeScreen.php on line 7 Here is the top of my updated code: <?php $title = $_GET[title]; $title = str_replace(" ","%20",$title); $name = $_GET[name]; exec('webshotcmd.exe /url "http://www.myurl.com/preview.php?prev='.$title.'" /out "images/$name" /width "300" /height "240" /bwidth "768" /bheight "1024"') Quote Link to comment Share on other sites More sharing options...
Guest Posted March 14, 2008 Share Posted March 14, 2008 Two things: a) I noticed there was no semicolon at the end of the exec() call, that may have been a copy/paste problem, but check it out. b) Is the exec() call the 7th line of the program? Another thing you could try: is placing the command into a separate variable. Some system functions don't like variable substitution (I think). <?php $title = $_GET[title]; $title = str_replace(" ","%20",$title); $name = $_GET[name]; $command = 'webshotcmd.exe /url "http://www.myurl.com/preview.php?prev='.$title.'" /out "images/$name" /width "300" /height "240" /bwidth "768" /bheight "1024"'; exec($command); Quote Link to comment Share on other sites More sharing options...
ElectricShaka Posted March 14, 2008 Author Share Posted March 14, 2008 Thanks again 8ball that fixed the Variable error but it's still not working. The code in the exec() is identical to code I would put in my command line on the windows computer to run that program and output the correct file but it doesn't do it I have the monitor up on the other computer and everything. I don't see the program even open up like it would if I manually put it in the command line. Quote Link to comment Share on other sites More sharing options...
Guest Posted March 14, 2008 Share Posted March 14, 2008 oh, there's another variable in your command: <?php $title = $_GET[title]; $title = str_replace(" ","%20",$title); $name = $_GET[name]; // fixed $command = 'webshotcmd.exe /url "http://www.myurl.com/preview.php?prev='.$title.'" /out "images/'.$name.'" /width "300" /height "240" /bwidth "768" /bheight "1024"'; exec($command); if that doesn't work, then I you might want to check your php.ini -- if safe_mode is on, exec won't work how you'd expect it to. Quote Link to comment Share on other sites More sharing options...
ElectricShaka Posted March 14, 2008 Author Share Posted March 14, 2008 I fixed that other variable and checked that safe mode is not turned on. The program still doesn't run. I even tried adding the path of the .exe to the environment variable's Path. Still no luck. ??? Quote Link to comment Share on other sites More sharing options...
Stooney Posted March 14, 2008 Share Posted March 14, 2008 Does the program you're running attempt to open a window? I remember reading something about Apache not having permissions to run program that open windows or something of the such. Quote Link to comment Share on other sites More sharing options...
ElectricShaka Posted March 15, 2008 Author Share Posted March 15, 2008 Yes I suppose it does. It opens a status window which stays open for the length of the execution...perhaps 5 seconds? Then it creates an image file. Quote Link to comment Share on other sites More sharing options...
ElectricShaka Posted March 15, 2008 Author Share Posted March 15, 2008 Ok I've been reading any documentation I can find on this stuff. I'm now trying the following 2 things and neither are working. <?php $title = $_GET[title]; $title = str_replace(" ","%20",$title); $name = $_GET[name]; $command = '/webshotcmd.exe /url "http://www.myurl.com/preview.php?prev='.$title.'" /out "images/'.$name.'" /width "300" /height "240" /bwidth "768" /bheight "1024"'; exec($command, $output, $return); print_r($output); print_r($return); which give me this when I run the page: Array ( ) 1 and then: $path = "C:/xampplite/htdocs/WebShot/"; $exe = "webshotcmd.exe"; $args = '/url "http://www.myurl.com/preview.php?prev='.$title.'" /out "images/'.$name.'" /width "300" /height "240" /bwidth "768" /bheight "1024"'; function execInBackground($path, $exe, $args = "") { global $conf; if (file_exists($path . $exe)) { chdir($path); if (substr(php_uname(), 0, 7) == "Windows") { pclose(popen("start \"bla\" \"" . $exe . "\" " . escapeshellarg($args), "r")); } else { exec("./" . $exe . " " . escapeshellarg($args) . " > /dev/null &"); } } else { echo "File didn't exist"; } } execInBackground($path, $exe, $args); I've tried modifying some permissions on my home server (running Xampplite) but I'm not sure if I did it correctly. The program still refuses to launch. Any help is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.