Page 1 of 1
Submit JSON using commandline?
Posted: Wed Mar 20, 2013 9:32 am
by Kukulkan
Hi,
I try to submit a JSON as comandline parameter.
I tried this one-liner to test:
Code: Select all
MessageRequester("Test", ProgramParameter(0) + #CRLF$ + ProgramParameter(1))
I did not manage to find out in which way the quotes have to be escaped to work.
I tried
\",
""",
^" and some others but with no success. Google is not helpful.
Any idea? How to submit double quotes in a commandline parameter?
Kukulkan
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 10:27 am
by Danilo
Is using GetCommandLine_() on Windows an option for you?
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 10:59 am
by Kukulkan
Hi Danilo,
Thanks, but there are multiple parameters. So I have to do all the parsing by myself. I believe this is something that should be handled by the Operating System or at least by the development environment (PB). Or am I wrong? I have no problems with this on MacOS and Linux.
Is there a valid way for Windows to submit strings containing double quotes as commandline parameters?
Kukulkan
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 11:25 am
by Shield
The correct way of escaping quotes under Windows is "hello ""pb"" world",
which will result in >>hello "pb" world<<. Unfortunately this doesn't work
with PB's parameter commands as it seems that PB is screwing this up.
I did a quick test with another language and it worked flawlessly.
Couldn't get it to work under PB. Maybe you can try a WinAPI approach
using GetCommandLine_() and CommandLineToArgvW().
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 12:48 pm
by Little John
If no other trick will work, maybe you can pass
on the command line, and then your program replaces
' with
" ?
Just an idea.
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 4:24 pm
by Edwin Knoppert
afaik json does not contain crlf's
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 4:27 pm
by Shield
Well that's depending on the programmer, of course.
There is no such limitation.
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 8:00 pm
by Edwin Knoppert
He prepared a 'stringified' json and not an object view notation, both element as value have quotes.
Afaik in that case crlf is not part of json.
Re: Submit JSON using commandline?
Posted: Wed Mar 20, 2013 8:31 pm
by Shield
Of course you can use line breaks.
But maybe I'm just completely wrong...

Re: Submit JSON using commandline?
Posted: Thu Mar 21, 2013 12:33 am
by normeus
once you start escaping and adding quotes after quotes then you are still hand processing each parameter.
I use a few simple rules: no double quotes unless there are spaces, the colon should be together with key and space
on both sides of comma.
Code: Select all
yourprogram.exe { position: relevant , json: "not for CMD" }
this will give index
(0) "{"
(1) "position:" notice how there is no space btw ":" and key
(2) "relevant"
(3) , comman
(4) "json:" again with the colon attached to key
(5) "not for CMD" here the quotes have served their purpuse of keeping spaces in place
(6) "}" end of the whole thing