I'm trying to run a python script using PowerShell. In that python script I try to use a command line argument which includes double quotes and whitespace, which does not work properly. I suspect it to be an issue with PowerShell.
The (simplified) python script looks like this:
import sys
print(sys.argv[1])
The following calls and outputs show the problem
python script.py --arg=foo
--arg=foo
python script.py --arg='\"foo\"'
--arg="foo"
python script.py --arg='\"fo o\"'
--arg="fo
But what I need in the end is
--arg="fo o"
It strips away everything after the whitespace. I tested the same script in a Linux bash where it worked (with double quotes around the foo). This seems not to be a python issue but a PowerShell problem, can anyone help me? In the end I want to have a full JSON-String as the argument.
python .\script.py '--arg="""fo o"""'I get--arg="fo o". But seriously. Microsoft. wt...?python .\script.py '"--arg=\"fo o\""'. The outermost set of quotes defines the token as a string for PowerShell. The outer set of double quotes is for passing the entire token with the inner (escaped) double quotes to the Python process. With that said, why are you trying to pass arguments like that instead of useingargparse?