jxcore

How to pass arguments to a JXCore native application?


I created a NodeJS application and I used JXCore with the -native flag to produce a stand alone .exe. Now I'm trying to run the application and to pass some command line arguments.

It is working fine with the NodeJS app but not with the exe:

c:\project> node MyApp.js -arg1 bla
OK.

Works fine. But

c:\project> jx package MyApp.js MyApp -native
c:\project> MyApp.exe -arg1 bla
Error, please provide argument arg1.

I went through the documentation about packaging and some blog posts about the same. I am not able to find how to do it. Any idea?

Thanks!


Solution

  • It's exactly the same but there is a minor difference for compiled apps. For the command line below;

    jx myapp.js arg1 arg2

    The process arguments are;

    process.argv == [ 'jx' , 'myapp.js', 'arg1', 'arg2' ]

    When you compile myapp.js into myapp.exe, you would simply call;

    myapp.exe arg1 arg2

    hence the process arguments would be;

    process.argv == [ 'myapp.exe', 'arg1', 'arg2' ]

    You may use a trick in order to switch easily between compiled or non-compiled apps;

    if(process.IsEmbedded) process.argv.unshift(process.argv[0]);
    

    So, for a compiled app, the result would be: [ 'myapp.exe', 'myapp.exe', 'arg1', 'arg2' ], with arg1 and arg2 located at the same indices as when it is run using jx (non-compiled).