Forum > LazUtils

Expected behaviour of StrToCmdLineParam in LazFileUtils?

(1/2) > >>

Laz 1.2.2/FPC 2.6.4 - Windows 8.  Also confirmed under Laz Trunk/FPC Trunk.

Where would I be expected to use StrToCmdLineParam? 

I *think* I've found a bug, but I'm doubtful as this seems like a common function, so maybe it's being used incorrectly.

When I run the following

--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
  s: String;
  s := 'C:\Program Files';
--- End code ---

I expect to see "C:\Program Files" as the result (" or double quotes are expected on the command line for file/folder names with spaces on them).
Instead I see 'C:\Program Files'

This is causing an issue in the Lazarus-CCR package mplayer.  Any filenames with spaces passed to Filename don't get played.  I've changed the relevant line in MPLayerCtrl.pas, confirming it's definitely StrToCmdLineParam at fault.  I do know spaces in filenames causes problem for the mplayer package under Linux as well, but am not in a position to confirm if it's the single quotes at fault there, or some other issue.

So, either mplayer is incorrectly using StrToCmdLineParam (on at least Windows), or StrToCmdLineParam is returning incorrect values.   I can't find any useful documentation on StrToCmdLineParam, so I'm really not sure which issue to report/try to fix, so am looking for advice from you guys :-)

More Information:  StrToCmdLineParam is behaving as it's designed to behave (see comments in code below, this is directly from LazFileUtils.pas), so I'm kind of leaning towards it's use in mplayer is incorrect, on the other hand - I can't imagine when StrToCmdLineParam as is would be useful...

--- Code: ---function StrToCmdLineParam(const Param: string): string;
{ <empty> -> ''
  word -> word
  word1 word2 -> 'word1 word2'
  word's -> "word's"
  a" -> 'a"'
  "a" -> '"a"'
  'a' -> "'a'"
  #0 character -> cut the rest
  NoQuot = ' ';
  AnyQuot = '*';
  Quot: Char;
  p: PChar;
  i: Integer;
--- End code ---

I moved away from using StrToCmdLineParam in mplayer (in fact completely redesigned away from using .commandline), and that resolved the issue of filenames with spaces in them...

Still no idea where that function would be useful, but definitely not in Command Line Parameters for most programs under Windows...

The constant issues found with quoting etc and little platform differences in quoting (e.g. -Ofilename.ext with a spaced filename will be encoded "-Ofile name.ext" on *nix and -O"File name.ext" on Windows), were the reason to steer away from a cmdline as principle for TProcess. It was simply to fragile.

Thanks for that Marco, but I wasn't chasing an explanation of why .Commandline is deprecated in some places.

This topic is about StrToCmdLineParam.

--- Quote ---Where would I be expected to use StrToCmdLineParam? 
--- End quote ---

In both the scenarios you've described StrToCmdLineParam fails.   My question is:

 Is this a bug an issue?

I can't answer that, since I only work on TProcess, not the Lazarus side of it. IMHO anything -UTF8 is only a stopgap till real unicode support arrives (in trunk)


[0] Message Index

[#] Next page

Go to full version