Filenames with spaces in them passed as paramters lazarus / 32-Linux ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-21 15:11 How would a command line program under linux expect a filename with spaces in it to be passed. Under windows, double quotes do the job "", and the function I've found that does this well is AnsiQuotedStr. Will this work under Linux? ---------------------------------------------------------------------- Leledumbo · 2014-06-21 15:30 I'd say that's shell specific, but at least bash does it the same. ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-21 17:03 Quote from: Leledumbo on June 21, 2014, 05:30:58 pmI'd say that's shell specific, but at least bash does it the same. Thanks for this. If it is shell specific, don't suppose we've got a function somewhere that handles that already?  If not, then I'll stick double quoting.  Bash will cover most users nowadays... I've already confirmed that StrToCmdParam doesn't do what I think it would... ---------------------------------------------------------------------- hinst · 2014-06-21 18:34 Quote from: Mike.Cornflake on June 21, 2014, 05:11:23 pmHow would a command line program under linux expect a filename with spaces in it to be passed. Unsurprisingly, it should expect it surrounded by double quotes But it depends on the program, of course. Most command line utilities understand this syntax, but it is possible that some old _or_ rare _or_ no longer maintained programs can have problems with file paths containing spaces If you want to pass a file path to program, then just put double quotes around it. It is not necessary for filepaths without spaces, but it does not hurt either ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-21 19:17 Quote from: hinst on June 21, 2014, 08:34:23 pmUnsurprisingly, it should expect it surrounded by double quotes ... It is not necessary for filepaths without spaces, but it does not hurt either Many thanks hinst, appreciate it. AnsiQuotedStr already takes care of not wrapping the name with " if no spaces, so that's good. ---------------------------------------------------------------------- marcov · 2014-06-23 15:25 Quotes group arguments in bash, not filenames. If filenames are a separate argument  (like in -o "filename"), then it doesn't matter A common exception is if you parameters of the form -ofilename.ext.  On Windows then you do -o"filename with space" while on *nix you write "-ofilename with space" ---------------------------------------------------------------------- Mike.Cornflake · 2014-06-23 15:29 Quote On Windows then you do -o"filename with space" while on *nix you write "-o filename with space" Good to know.  My particular use case is mplayer, and for that the filename is a separate argument.  I've now had a chance to test on Linux, and can confirm just double quotes around the filename for mplayer worked as expected. Many thanks. ---------------------------------------------------------------------- bylaardt · 2014-07-05 18:52 sometimes you must (or can) use parameters with the escape char "\" before the space, something like that: my\ file\ name.ext ---------------------------------------------------------------------- marcov · 2014-07-06 15:23 Quote from: bylaardt on July 05, 2014, 08:52:19 pmsometimes you must (or can) use parameters with the escape char "\" before the space, something like that: my\ file\ name.ext For most shells that is possible, and double \\ to form a \. Note that when you execute on system level, without executing a new shell, no escaping whatsoever is allowed. ---------------------------------------------------------------------- bylaardt · 2014-07-06 18:17 what you mean with "system level"? everytime i use \ it works to me! have you a example when it doesn't works? maybe i must reevaluate my applications... ---------------------------------------------------------------------- Leledumbo · 2014-07-07 10:20 Quote from: bylaardt on July 06, 2014, 08:17:15 pmwhat you mean with "system level"? everytime i use \ it works to me! have you a example when it doesn't works? maybe i must reevaluate my applications... System level = not through any shell