Passing http arguments to main as argc/argv?

1,225 views
Skip to first unread message

Robert Goulet

unread,
Sep 10, 2015, 11:51:35 AM9/10/15
to emscripten-discuss
Hi all,

Is it possible to have an Emscripten generated html to take the http parameters (GET or POST) and pass them to the C/C++ main as argc/argv?

For example, browsing to:


I would expect that in int main(int argc, char* argv[]) contains:

argc = 5
argv[0] = "index.html"
argv[1] = "param1"
argv[2] = "hello"
argv[3] = "param2"
argv[4] = "42"

Or is there something equivalent that works just as well?

Thanks!

Alon Zakai

unread,
Sep 10, 2015, 1:47:11 PM9/10/15
to emscripten-discuss
main() argc/argv are set from Module.arguments, which is just a list of strings. You could copy the GET params from the url into that. I don't think we have a utility anywhere to do it automatically, although maybe emrun does that?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jukka Jylänki

unread,
Sep 10, 2015, 2:17:23 PM9/10/15
to emscripte...@googlegroups.com
Emrun by default routes GET parameters to an array Module.arguments = []; , which Emscripten apps read by default to argc+argv. It's a very short snippet of code: https://github.com/kripken/emscripten/blob/master/src/emrun_prejs.js . Though emrun is generally used by automating command line runs of a compiled page, so you may just want to copy that code to your shell .html file (and pass the linker flag --shell-file myshell.html to use it). 

Robert Goulet

unread,
Sep 11, 2015, 2:33:52 PM9/11/15
to emscripten-discuss
Ah I see, good thing we can override the HTML with this --shell-file parameter, very nice. I still believe that passing GET parameters to argv/argc would be done by the default shell file thought.

Thanks!


On Thursday, September 10, 2015 at 2:17:23 PM UTC-4, jj wrote:
Emrun by default routes GET parameters to an array Module.arguments = []; , which Emscripten apps read by default to argc+argv. It's a very short snippet of code: https://github.com/kripken/emscripten/blob/master/src/emrun_prejs.js . Though emrun is generally used by automating command line runs of a compiled page, so you may just want to copy that code to your shell .html file (and pass the linker flag --shell-file myshell.html to use it). 
2015-09-10 20:47 GMT+03:00 Alon Zakai <alon...@gmail.com>:
main() argc/argv are set from Module.arguments, which is just a list of strings. You could copy the GET params from the url into that. I don't think we have a utility anywhere to do it automatically, although maybe emrun does that?
On Thu, Sep 10, 2015 at 8:51 AM, Robert Goulet <robert...@autodesk.com> wrote:
Hi all,

Is it possible to have an Emscripten generated html to take the http parameters (GET or POST) and pass them to the C/C++ main as argc/argv?

For example, browsing to:


I would expect that in int main(int argc, char* argv[]) contains:

argc = 5
argv[0] = "index.html"
argv[1] = "param1"
argv[2] = "hello"
argv[3] = "param2"
argv[4] = "42"

Or is there something equivalent that works just as well?

Thanks!

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Jukka Jylänki

unread,
Sep 11, 2015, 3:25:32 PM9/11/15
to emscripte...@googlegroups.com
It's a tricky question since a lot of pages use GET parameters as completely orthogonal things. Btw, the --shell-file is actually a bit cosmetic, since one can also do "emcc x.cpp -o x.js" and then manage the .html file completely by other custom means, so the --shell-file is kind of a conveniency to set up a shell html when -o .html is specified. (or that was the case the last I investigated, I don't think we have overloaded custom meanings there, except perhaps for --proxy-to-worker.. hmm..)

2015-09-11 21:33 GMT+03:00 Robert Goulet <robert...@autodesk.com>:
Ah I see, good thing we can override the HTML with this --shell-file parameter, very nice. I still believe that passing GET parameters to argv/argc would be done by the default shell file thought.

Thanks!

On Thursday, September 10, 2015 at 2:17:23 PM UTC-4, jj wrote:
Emrun by default routes GET parameters to an array Module.arguments = []; , which Emscripten apps read by default to argc+argv. It's a very short snippet of code: https://github.com/kripken/emscripten/blob/master/src/emrun_prejs.js . Though emrun is generally used by automating command line runs of a compiled page, so you may just want to copy that code to your shell .html file (and pass the linker flag --shell-file myshell.html to use it). 
2015-09-10 20:47 GMT+03:00 Alon Zakai <alon...@gmail.com>:
main() argc/argv are set from Module.arguments, which is just a list of strings. You could copy the GET params from the url into that. I don't think we have a utility anywhere to do it automatically, although maybe emrun does that?
On Thu, Sep 10, 2015 at 8:51 AM, Robert Goulet <robert...@autodesk.com> wrote:
Hi all,

Is it possible to have an Emscripten generated html to take the http parameters (GET or POST) and pass them to the C/C++ main as argc/argv?

For example, browsing to:


I would expect that in int main(int argc, char* argv[]) contains:

argc = 5
argv[0] = "index.html"
argv[1] = "param1"
argv[2] = "hello"
argv[3] = "param2"
argv[4] = "42"

Or is there something equivalent that works just as well?

Thanks!

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages