Problem with my system call

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swanley007
Forum Newbie
Posts: 5
Joined: Mon Aug 14, 2006 9:27 am

Problem with my system call

Post by swanley007 »

Hello;

I am working on an Apache environment with Windows Server 2003 as the OS. I am trying to execute a system call/program that I built.

The program is called test.exe and takes some parameters:

My code is as follows(NOTE the test.exe is debugged and working via the command line)

Code: Select all

<?php
//exec('e:\backup',$out_arr, $retval);
exec("c:\backup_program\test c:\progra~1\postgresql\8.1\bin localhost focus \\\10.1.2.7\SISBACKUP",$out_arr, $retval);
for($i = 0; $i<=sizeof($out_arr);$i++)
{
echo $out_arr[$i]."<p>";
}

echo "<p><p>RETURN VAL: " .$retval; 
?>


AND this is the output....

c:\progra~1\postgresql\8.1\bin\pg_dump -h localhost -U swanley007 focus > \\10.1.2.7\SISBACKUP\Backup-Mon-Aug-14-10-52-19-2006.backup





RETURN VAL: 0



If I run the program without any options, ie

Code: Select all

system('c:\backup_program\test');....
I get the error as it would be returned from the command line. I am not sure what to do. I am somewhat unfamiliar with the system and ecxec functions in php. Also, note that I have written a batch file to call the program, and I works fine as well, so I am confident that my proble is in the php.


Thanks
Stan Swank II
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

escape all the backslash characters. \ should be \\, \\ should be \\\\, etc

The reason why it's breaking: \t is a tab in the context (double quote string) you are using.
swanley007
Forum Newbie
Posts: 5
Joined: Mon Aug 14, 2006 9:27 am

Post by swanley007 »

Changed code to...

Code: Select all

<?php
//exec('e:\backup',$out_arr, $retval);
exec("c:\\backup_program\\test c:\\progra~1\\postgresql\\8.1\\bin localhost focus \\\\10.1.2.7\\SISBACKUP",$out_arr, $retval);
for($i = 0; $i<=sizeof($out_arr);$i++)
{
echo $out_arr[$i]."<p>";
}

echo "<p><p>RETURN VAL: " .$retval; 
?>

output is now...
c:\progra~1\postgresql\8.1\bin\pg_dump -h localhost -U swanley007 focus > \\10.1.2.7\SISBACKUP\Backup-Mon-Aug-14-11-06-05-2006.backup





RETURN VAL: 0


Still no luck
swanley007
Forum Newbie
Posts: 5
Joined: Mon Aug 14, 2006 9:27 am

Post by swanley007 »

OK ALL... I have been using google and some other tools to try and fix this problem. I tried a bump, but got in trouble! Here is the different commands I have tried thus far with no avail...

exec('e:\backup',$out_arr, $retval); -- This is a bat file to call the program with perams

exec("c:\\backup_program\\test c:\\progra~1\\postgresql\\8.1\\bin localhost focus \\\\10.1.2. \\SISBACKUP",$out_arr, $retval);


echo `C:/path/to/application.exe`; -- I did try with the params for the program


//passthru("c:\\backup_program\\test c:\\progra~1\\postgresql\\8.1\\bin localhost focus \\\\10.1.2.7\\SISBACKUP");


$retval = shell_exec("c:\\backup_program\\test c:\\progra~1\\postgresql\\8.1\\bin localhost focus \\\\10.1.2.7\\SISBACKUP";


So i hope this helps someone to help me in finishing up this little problem...It is very time sensitive!!!!!
swanley007
Forum Newbie
Posts: 5
Joined: Mon Aug 14, 2006 9:27 am

Post by swanley007 »

For all of those interrested, i have solved the problem.

The problem was that Apache was being run as a local system account with desktop interraction.

I needed it to be run as a service as a specific user and pass...specifically on that is able to access the SMB share.


FYI
Post Reply