Accueil du site > INFORMATIQUE > PHP > PHP, Windows and `command line` programs output mystery
lundi 17 octobre 2005, par
Not all dos programs stdout streams are caught by PHP
Recently I tried to replace my CvsWeb for windows (aka cvswebnt), a Perl script to browse CVS repositories. I use it to browse my local cvs repository for a long time, but this script is not supported (at least the Windows version), and I can’t modify the code myself to correct the few bugs. I found browsecvs on Sourceforge site, a PHP script with similar features. It seems there is not much support for it too, but at least I can modify it myself. However I ran into a problem I am not able to solve.
The original code use this command to get revision details :
$conf['cvsrep'] = array(['cvsroot@sunshine'->mailto:'cvsroot@sunshine'] = '/home/cvsroot/',
);
$conf['bin']['rlog'] = '/usr/bin/rlog';
$f = EscapeShellCmd($file);
$rlog = $conf['bin']['rlog'];
exec("$rlog $f,v",$output);on a Unix system, the exec command should expand with :
exec("/usr/bin/rlog /home/cvsroot/module_directory/file_name,v",$output);and the output of this command should fill the $log variable. Right. On my Windows system I just changed :
$conf['cvsrep'] = array(
['cvsroot@sunshine'->mailto:'cvsroot@sunshine'] = 'X:\\My_programs_dir\\cvs\\my_repository\\',
);
$conf['bin']['rlog'] = 'X:\\My_programs_dir\\cvs\\Cvsnt\\rlog.exe';But this does not work. I will not detail all things I tried to make this code working. In short, I tried to replace double backslashes with single slash, to use COM PHP functions :
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Exec("$rlog $f,v");
or
$WshShell-Run("$rlog $f,v", 0, true);or “passthru” and “system” functions and tried to (either with ’exec’ or COM functions) redirect the output of the dos command to a file and then read the file, without more success. The output file is created, but not filled. Until I discovered a strange behavior. It seems that some command line programs outputs are properly ’captured’ by PHP, whether other are not. It does not matter which PHP feature you use to run the command (either native “exec”, “system”… command or COM “WScript.Shell->Run” or Exec), it depends all of the program you try to run.
For example, with a dos box, if I type any dos program :
>C:\util\hardlink.exeOutput :
> Hardlink - JCB © 2000
> =====================
> Syntaxe :
> ---------
> hardlink
and with php :
exec('C:\\util\\hardlink.exe', $output);
print_r($output);Output :
> Hardlink - JCB ¸ 2000 ===================== Syntaxe : --------- hardlink : le nom du fichier ou dossier pour lequel on veut créer un lien : l’emplacement du lien 1
It works. If I try another program, rlog.exe :
Dos box :
>c:\cvs\rlog.exeOutput (only the first line ..) :
> Usage : cvs rcsfile [-lRhtNb] [-r[revisions]] [-d dates] [-s states]
with php :
exec('C:\\cvs\\rlog.exe', $output);
print_r($output);Output :
> Array ( )
??? I tried some command line programs on my system, and without any meaningful reason, some programs fill the $output variable, some other not. I am connected with an administrator account, so I don’t think this is an authorization issue.
5 Messages de forum