0

I have a batch that I am running at the end of an installer process so that the end-users have as minimal an input as possible.

Everything with the .exe and the batch file are functioning grand. I have got a generic VBScript that performs the function of finding a string and replacing it. I have tested it on a simple string in the batch file and it works fine as below to activate the VBScript and make it perform the find and replacement.

Find_And_Replace.vbs "46233.xml" "DuchessLoco_1" "DuchessLoco_10"

The problem comes that I want the strings to Find and Replace to be far more detailed and it cannot read the characters that I'm typing in to the quotation marks.

I gather this may be because the batch itself understands certain characters that need escaping and then the VBScript will require other ones escaping in a different way. This is where my understanding is letting me down - but I am loathe to make the vbs file more bespoke as it being generic suits the fact I will have multiple different uses for it with multiple different installers over time. Below is an example of the string that I want to Find and modify. The VBScript is executing but not finding hence replacing the string likely due to my errors.

c:"deltaString">DuchessLoco_1</Name>

I have put this in my code as:

"c:\"deltaString\">DuchessLoco_1</Name>"

and this is the string that is failing to be found by the VBScript- I shall later need to move on to using more complex characters such as Tab and New line, so if it isn't possible via this method I will have to rethink my approach to the problem.

user692942
  • 16,398
  • 7
  • 76
  • 175
M. Wilson
  • 19
  • 3
  • This isn't a duplicate of either linked question, b/c it's not about stripping quotes from arguments (quite the opposite), and escaping double quotes simply doesn't work (for some reason unknown to me all double quotes are removed from arguments passed to VBScript regardless of how they're escaped). There are a few ugly workarounds (see [this related question](https://stackoverflow.com/q/4192376/1630171)), but frankly, a better solution for your problem would be to rewrite your batch script in PowerShell. – Ansgar Wiechers Oct 20 '18 at 12:33
  • Okay Ansgar, thanks for the tip, I am not that familiar with Powershell but I shall have to investigate it a little further. – M. Wilson Oct 20 '18 at 12:35
  • It is not possible to pass double quote literals to CSCRIPT, regardless whether using JScript or VBScript. There is no escape sequence for double quotes - they are always stripped from the argument. You should check out [JREPL.BAT](https://www.dostips.com/forum/viewtopic.php?f=3&t=6044). With the JREPL `/X` option you can use `\q` as an escape sequence to represent a double quote literal. Since you are doing a literal search you would also need the `/L` option. But you should checkout the regular expression features. – dbenham Oct 20 '18 at 12:47
  • 5
    And while you are at it, learn to properly read and write XML. Powershell, Vbscript and Jscript all have native methods to do so. – Squashman Oct 20 '18 at 14:03

0 Answers0