TheFluffyOne Posted January 12, 2009 Share Posted January 12, 2009 I am parsing INI files for entries used to launch other processes. A stripped-down example of such a file might be:[global] command=wscript.exe commandline="c:\some folder\with spaces\myscript.vbs"I'm using IniRead to grab these values like so:$commandName = IniRead("test.ini", "global", "command", "") $commandParams = IniRead("test.ini", "global", "commandline", "") $fullCommand = $commandName & " " & $commandParams ConsoleWrite($fullCommand)However IniRead is stripping the quotes from the value, so the output of the script is:wscript.exe c:\some folder\with spaces\myscript.vbsIn the full script this fails because wscript.exe tries to load a script called "c:\some". If, however, I have a value that doesn't start and end with a quote, the path is quoted as expected. An example of an INI file that would work:[global] command=wscript.exe commandline="c:\some folder\with spaces\myscript.vbs" scriptinput.txtThe output when using this as input is:wscript.exe "c:\some folder\with spaces\myscript.vbs" scriptinput.txtIs this expected behaviour? If so, does this mean I'm going to have to write my own INI parser to work around this behaviour? (Note that the INI files are from an old system, which is why I can't just alter the input file format). Link to comment Share on other sites More sharing options...
Pain Posted January 12, 2009 Share Posted January 12, 2009 Try with single quote '"c:\some folder\with spaces\myscript.vbs"' Link to comment Share on other sites More sharing options...
Valuater Posted January 12, 2009 Share Posted January 12, 2009 I'm thinking it might be easier to change this... $commandName = IniRead("test.ini", "global", "command", "") $commandParams = IniRead("test.ini", "global", "commandline", "") $fullCommand = $commandName & ' "' & $commandParams & '"' ConsoleWrite($fullCommand) 8) Link to comment Share on other sites More sharing options...
TheFluffyOne Posted January 12, 2009 Author Share Posted January 12, 2009 Try with single quote '"c:\some folder\with spaces\myscript.vbs"'I don't understand how this would resolve the problem. Could you explain please? Link to comment Share on other sites More sharing options...
TheFluffyOne Posted January 12, 2009 Author Share Posted January 12, 2009 I'm thinking it might be easier to change this... $commandName = IniRead("test.ini", "global", "command", "") $commandParams = IniRead("test.ini", "global", "commandline", "") $fullCommand = $commandName & ' "' & $commandParams & '"' ConsoleWrite($fullCommand)The problem here is that my second example gets mangled to: wscript.exe ""c:\some folder\with spaces\myscript.vbs" scriptinput.txt" This also won't launch. I need to cope with entries that are completely enclosed in quotes as well as those that are not. Link to comment Share on other sites More sharing options...
Pain Posted January 12, 2009 Share Posted January 12, 2009 $commandName = IniRead("test.ini", "global", "command", "") $commandParams = IniRead("test.ini", "global", "commandline", "") $fullCommand = '"' & $commandName &'" ' & '"' &$commandParams & '"' ConsoleWrite($fullCommand) Link to comment Share on other sites More sharing options...
TheFluffyOne Posted January 12, 2009 Author Share Posted January 12, 2009 $commandName = IniRead("test.ini", "global", "command", "") $commandParams = IniRead("test.ini", "global", "commandline", "") $fullCommand = '"' & $commandName &'" ' & '"' &$commandParams & '"' ConsoleWrite($fullCommand)Suffers from the same problem as the suggestion by Valuater, unfortunately. Thanks anyway. Btw, the font you are looking for (the Common Tasks pane font) is 8pt Tahoma Bold with anti-aliasing disabled. Link to comment Share on other sites More sharing options...
ResNullius Posted January 12, 2009 Share Posted January 12, 2009 Can you add single quotes around the values when you write them to the ini file, regardless of whether they have double quotes or not[global]command=wscript.execommandline='"c:\some folder\with spaces\myscript.vbs"' Link to comment Share on other sites More sharing options...
TheFluffyOne Posted January 13, 2009 Author Share Posted January 13, 2009 (edited) Can you add single quotes around the values when you write them to the ini file, regardless of whether they have double quotes or notThe INI files are historical files supplied from elsewhere. For various reasons it is not a good idea for us to modify these. Edited January 13, 2009 by TheFluffyOne Link to comment Share on other sites More sharing options...
youknowwho4eva Posted January 13, 2009 Share Posted January 13, 2009 (edited) $result = stringtrimright($commandName,stringlen($commandName)-1) if $result = '"' then else endif fill in the blanks Edit: forgot the -1 Edited January 13, 2009 by youknowwho4eva Giggity Link to comment Share on other sites More sharing options...
saywell Posted January 13, 2009 Share Posted January 13, 2009 Would IniReadSection have the same problem? William Link to comment Share on other sites More sharing options...
ResNullius Posted January 14, 2009 Share Posted January 14, 2009 Would IniReadSection have the same problem?Williamfrom: http://en.wikipedia.org/wiki/INI_fileQuoted valuesSome implementations allow values to be quoted, typically using double quotes and/or apostrophes. This allows for explicit declaration of whitespace, and/or for quoting of special characters (equals, semicolon, etc.). The standard Windows function GetPrivateProfileString supports this, and will remove quotation marks that surround the values.That's why I suggested the single quotes when writing the ini valuesI think the final solution is going to involve RegExp on the values when they're read: if they have a space in them but don't have quotes then add the quotes? Or some such... Link to comment Share on other sites More sharing options...
ResNullius Posted January 14, 2009 Share Posted January 14, 2009 (edited) The problem here is that my second example gets mangled to: wscript.exe ""c:\some folder\with spaces\myscript.vbs" scriptinput.txt" This also won't launch. I need to cope with entries that are completely enclosed in quotes as well as those that are not.@TheFluffyOne In your ini for the second example [global] command=wscript.exe commandline="c:\some folder\with spaces\myscript.vbs" scriptinput.txt does the parameter "scriptinput.txt" ever have a space in it, like "script input.txt" or does it ever have a full path as well, like "c:\some other folder\scriptinput.txt" ? Edit: Answered one of my own questions and changed it to get clarification. Edited January 14, 2009 by ResNullius Link to comment Share on other sites More sharing options...
TheFluffyOne Posted January 14, 2009 Author Share Posted January 14, 2009 does the parameter "scriptinput.txt" ever have a space in it, like "script input.txt" or does it ever have a full path as well, like "c:\some other folder\scriptinput.txt" ?Yes, in some cases the path will have spaces and when this happens it will be quoted like so: [global] command=wscript.exe commandline="c:\some folder\with spaces\myscript.vbs" "c:\Program Files\Noddy Program\fixme.txt" Link to comment Share on other sites More sharing options...
ResNullius Posted January 14, 2009 Share Posted January 14, 2009 Yes, in some cases the path will have spaces and when this happens it will be quoted like so: [global] command=wscript.exe commandline="c:\some folder\with spaces\myscript.vbs" "c:\Program Files\Noddy Program\fixme.txt"Can you post an ini that has all possible combinations of entries as you would encounter them: ie: quoted paths, unquoted paths, unquoted with spaces in the "scriptinput.txt" parameter, etc. It will help immensely in developing a solution that works for all instances; rather than figure one out and then find out it doesn't work for another example. Also, are all your paths when referenced using actual drive letters: "C:" "D:", etc, or do some reference network paths "\\Server\folder with space\myscript.vbs"? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now