php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39234 Retrieve short names to files
Submitted: 2006-10-23 12:37 UTC Modified: 2011-06-11 10:15 UTC
From: RQuadling at GMail dot com Assigned: pajoye (profile)
Status: Closed Package: Filesystem function related
PHP Version: * OS: Windows only
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 - 25 = ?
Subscribe to this entry?

 
 [2006-10-23 12:37 UTC] RQuadling at GMail dot com
Description:
------------
Hello.

(I was required to pick a version, but that is not really relevant).

This issue extends from a bug/feature of the Windows command shell executable (cmd.exe) which only allows a single set of double quotes to be used when being used with the /C option.

e.g.

<?php
// Fine
exec('"C:\Program Files\Some Dir\Some Program" C:\somefile.txt');
// Not fine
exec('"C:\Program Files\Some Dir\Some Program" "C:\some file with a space in the name.txt"');
?>

You get an error which is the same at the command prompt.

These work (the parameter is useless).

C:\windows\system32\calc.exe 123
"C:\windows\system32\calc.exe" 123
C:\windows\system32\calc.exe "123"
"C:\windows\system32\calc.exe" "123"
cmd /c C:\windows\system32\calc.exe 123
cmd /c "C:\windows\system32\calc.exe" 123
cmd /c C:\windows\system32\calc.exe "123"

But this doesn't work at the command line.

cmd /c "C:\windows\system32\calc.exe" "123"

You get the error ...

'C:\windows\system32\calc.exe" "123' is not recognized as an internal or external command, operable program or batch file.


So, whilst this isn't a PHP bug, PHP could certainly help get around the problem.


My proposal is to either extend the PHP function realpath() to allow for a boolean parameter to indicate the short name is to be returned.

e.g.

string realpath ( string path [, boolean return_short_name] )

or to introduce 2 new functions

string shortname ( string longname )
string longname ( string shortname )


In addition, extending the SPL to have a getShortName() method.



To get the shortname within MS VC++, there is a function called GetShortPathName(). There is also GetLongPathName().

References to these functions can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getshortpathname.asp

and http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getlongpathname.asp

DWORD GetShortPathName(
  LPCTSTR lpszLongPath,
  LPTSTR lpszShortPath,
  DWORD cchBuffer
);

DWORD GetLongPathName(
  LPCTSTR lpszShortPath,
  LPTSTR lpszLongPath,
  DWORD cchBuffer
);


With the shortname() function, a filename like ...

C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql.exe

would become ...

C:\PROGRA~1\MI6841~1\80\TOOLS\BINN\OSQL.EXE

The name supplied is system dependent. I have a LOT of directories in "C:\Program Files" starting with Microsoft.

27/10/2004  15:01    <DIR>          MI3AA1~1     Microsoft ActiveSync
16/03/2006  11:13    <DIR>          MIAF83~1     Microsoft AntiSpyware
05/01/2005  10:02    <DIR>          MIDA86~1     Microsoft Baseline Security Analyzer
23/02/2005  16:17    <DIR>          MIAF01~1     Microsoft Firewall Client
27/10/2004  12:13    <DIR>          MICROS~1     microsoft frontpage
06/04/2006  09:22    <DIR>          MICROS~3     Microsoft IntelliPoint
06/04/2006  09:26    <DIR>          MICROS~2     Microsoft IntelliType Pro
06/04/2006  10:13    <DIR>          MICROS~4     Microsoft Office
29/10/2004  14:36    <DIR>          MI6841~1     Microsoft SQL Server
16/11/2004  16:31    <DIR>          MIAF9D~1     Microsoft Visual Studio
28/10/2004  08:44    <DIR>          MIF2B0~1     Microsoft Works
23/02/2005  12:02    <DIR>          MICROS~1.NET Microsoft.NET


In terms of impact, making 2 new functions which are Windows only would probably be easier.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 08:38 UTC] jani@php.net
-Summary: Retrieve short names to files. +Summary: Retrieve short names to files -Package: Feature/Change Request +Package: Filesystem function related -Operating System: Windows XP SP2 +Operating System: Windows only -PHP Version: 5CVS-2006-10-23 (snap) +PHP Version: *
 [2011-06-11 10:15 UTC] rquadling@php.net
-Status: Assigned +Status: Closed
 [2011-06-11 10:15 UTC] rquadling@php.net
As PHP now uses another feature of cmd.exe, this allows all elements of the 
command line (programs and parameters) to be quoted quite happily.

As such, this request is no longer needed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 07:01:29 2024 UTC