Jump to content

exec()


ElectricShaka

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.