Submit JSON using commandline?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Submit JSON using commandline?

Post by Kukulkan »

Hi,

I try to submit a JSON as comandline parameter.

Code: Select all

{ 
  "Foo": "Bar"
}
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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Submit JSON using commandline?

Post by Danilo »

Is using GetCommandLine_() on Windows an option for you?

Code: Select all

Debug PeekS(GetCommandLine_())
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Submit JSON using commandline?

Post 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
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Submit JSON using commandline?

Post 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().
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Little John
Addict
Addict
Posts: 4775
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Submit JSON using commandline?

Post by Little John »

If no other trick will work, maybe you can pass

Code: Select all

{
  'Foo': 'Bar'
}
on the command line, and then your program replaces ' with " ?
Just an idea.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Re: Submit JSON using commandline?

Post by Edwin Knoppert »

afaik json does not contain crlf's
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Submit JSON using commandline?

Post by Shield »

Well that's depending on the programmer, of course. :wink:
There is no such limitation.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Re: Submit JSON using commandline?

Post 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.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Submit JSON using commandline?

Post by Shield »

Of course you can use line breaks. :? :?:
But maybe I'm just completely wrong... :|
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Submit JSON using commandline?

Post 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
Post Reply