Php system problem

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
dbrock178
Forum Newbie
Posts: 10
Joined: Sun Aug 19, 2007 1:08 am

Php system problem

Post by dbrock178 »

Hello all,

I am currently having a problem calling certain executable files using PHP 4.4.2 and Windows XP. I am currently trying to get GPG to encrypt a file for me using PHP.

If I do system('del c:\\temp\\order.txt',$retval); I have no problem with the command executing.

If I do
system ('C:\\Program Files\\GNU\\GnuPG\\gpg.exe -r jimmy --encrypt c:\\temp\\order.txt',$retval); nothing happens.

I created a small C program using the system function to call GPG and it worked fine, but when I tried to have PHP's system function call my C program nothing happens.

Any advice as to what the problem could be?

Thank you.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please try

Code: Select all

echo "<pre>gpg.exe\n";
flush();
passthru('C:\\Program Files\\GNU\\GnuPG\\gpg.exe -r jimmy --encrypt c:\\temp\\order.txt',$retval);
var_dump($retval);
echo "</pre>\n";
and post the output.
dbrock178
Forum Newbie
Posts: 10
Joined: Sun Aug 19, 2007 1:08 am

Post by dbrock178 »

gpg.exe
int(1)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and

Code: Select all

passthru('C:\\Program Files\\GNU\\GnuPG\\gpg.exe --help',$retval);
?
dbrock178
Forum Newbie
Posts: 10
Joined: Sun Aug 19, 2007 1:08 am

Post by dbrock178 »

Same thing as before.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

$path = 'C:\\Program Files\\GNU\\GnuPG';
// $path = 'C:\\Programme\\GNU\\GnuPG';

$cfile = $path . '\\volka_test.cmd';
$cmds = "C:
cd $path
cd
gpg.exe --help
echo done.";

file_put_contents($cfile, $cmds) or die('cannot write to '.$cfile);

passthru($cfile, $retval);
var_dump($retval);
unlink($cfile);
if that doesn't reveal something I'm clueless.
dbrock178
Forum Newbie
Posts: 10
Joined: Sun Aug 19, 2007 1:08 am

Post by dbrock178 »

Ok I messed around and got a little bit further.

I changed the code to passthru('gpg --help',$retval); and got the help info to output back to the browser.
I also imported a public key since when PHP runs GPG it doesn't see the public key that I was seeing when I ran the command.

Now the problem is that when I run
passthru('gpg -r jimmy --output s.txt --encrypt c:\\temp\\order.txt',$retval);

the browser just keeps waiting and the file still isn't encrypted.
dbrock178
Forum Newbie
Posts: 10
Joined: Sun Aug 19, 2007 1:08 am

Post by dbrock178 »

Ok I got it working thanks to another site that listed additional arguments.
Also PHP doesn't seem to like binary output from GPG.

Here is the working command if anyone ever needs it.
passthru('gpg --always-trust -a -r $recp -e $filetoencrypt',$retval);

Also thank you Volka for your help.
Post Reply