Page 1 of 1

Php system problem

Posted: Sun Aug 19, 2007 2:15 am
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.

Posted: Sun Aug 19, 2007 4:17 am
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.

Posted: Sun Aug 19, 2007 4:37 am
by dbrock178
gpg.exe
int(1)

Posted: Sun Aug 19, 2007 4:44 am
by volka
and

Code: Select all

passthru('C:\\Program Files\\GNU\\GnuPG\\gpg.exe --help',$retval);
?

Posted: Sun Aug 19, 2007 5:04 am
by dbrock178
Same thing as before.

Posted: Sun Aug 19, 2007 5:42 am
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.

Posted: Sun Aug 19, 2007 6:05 am
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.

Posted: Sun Aug 19, 2007 11:26 am
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.