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"); Link to comment https://forums.phpfreaks.com/topic/96092-exec/ 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"') Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-491925 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"') Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-491930 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); Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-491935 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. Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-491944 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. Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-491968 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. ??? Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-491975 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. Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-491978 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. Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-492627 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. Link to comment https://forums.phpfreaks.com/topic/96092-exec/#findComment-492650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.