I am executing a Python script using a PowerShell command, The Python script takes a string that could contain special characters inside it. This parameter is passed from an ansible pipeline. So, the solution should be a general one that can be applied to any string. The PowerShell version I am running is PowerShell 5.1
python.exe script.py --special_string the"str`in'g
But this gives errors.
Based on my current findings,
- In PowerShell ‘ means a literal string and ” could be used to add variable values.
- As the escape character we use `, but the`”strin`’g gives an error. “the`”strin`’g” doesn’t work either.
- You cannot surround the string with ” using ‘ like ‘string”g’. This also gives an error.
- Backtick can be escaped using double backticks or surrounding the string with single quotes. (making it a literal string)
What is the best way to do this?