NodeJs-Unreal icon indicating copy to clipboard operation
NodeJs-Unreal copied to clipboard

pass command line arguments to the node script

Open xmak opened this issue 4 years ago • 5 comments

How do I pass command line arguments to the node script I want to execute?

I tried entering it in the "Default Script Path" field of the node component, but it gives me a "Cannot find module" error:

LogTemp: Error: Script Error: internal/modules/cjs/loader.js:638throw err; ^ Error: Cannot find module 'C:\Users\Marko\Downloads\NodeJSExamples\Content\Scripts\simple.js --test-param=1' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25)at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)at startup (internal/bootstrap/node.js:283:19)at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

xmak avatar Apr 19 '20 08:04 xmak

I don't believe commandline arguments are currently supported. It is expected to communicate with your script via ipc-event-emitter, see https://github.com/getnamo/nodejs-ue4#a-basic-adder for an example.

Adding commandline arguments would make a good enhancement though and shouldn't be too hard to add in theory. The related entry points would be https://github.com/getnamo/nodejs-ue4/blob/master/Source/CommandLine/Private/NodeCmd.cpp#L332, https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/nodeWrapper.js#L104, and https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/scriptHandler.js#L9. Looks like chopping up your scriptPath/name into args at https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/scriptHandler.js#L16 would probably do it.

getnamo avatar Apr 20 '20 05:04 getnamo

Hi.

I need to run a third party NodeJS script which accepts configuration via a command line parameters, so communicating via |ipc-event-emitter| is not an option in this case.

The proper way of doing this would be to allow arguments to be set in the RunScript blueprint node, but that's too much for my limited knowledge of your plugin, so I'll do a quickfix in the scriptHandler.js by chopping up the args with "|" as separator (because the script path might have spaces in it).

Do you accept pull requests?

On 20.04.2020. 07:13, Jan Kaniewski wrote:

I don't believe commandline arguments are currently supported. It is expected to communicate with your script via |ipc-event-emitter|, see https://github.com/getnamo/nodejs-ue4#a-basic-adder for an example.

Adding commandline arguments would make a good enhancement though and shouldn't be too hard to add in theory. The related entry points would be https://github.com/getnamo/nodejs-ue4/blob/master/Source/CommandLine/Private/NodeCmd.cpp#L332, https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/nodeWrapper.js#L104, and https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/scriptHandler.js#L9. Looks like chopping up your scriptPath/name into args at https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/scriptHandler.js#L16 would probably do it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/getnamo/nodejs-ue4/issues/15#issuecomment-616313763, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE2ZL3F27VAJ64J3VF4FM3RNPKWLANCNFSM4MLWBSGQ.

xmak avatar Apr 23 '20 06:04 xmak

Btw, when compiling the plugin, I get the following errors:

Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(5): fatal error C1083: Cannot open include file: 'PreWindowsApi.h': No such file or directory
Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(6): fatal error C1083: Cannot open include file: 'AllowWindowsPlatformTypes.h': No such file or directory
Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(18): fatal error C1083: Cannot open include file: 'HideWindowsPlatformTypes.h': No such file or directory
Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(19): fatal error C1083: Cannot open include file: 'PostWindowsApi.h': No such file or directory

This is easily fixed by appending "Windows/" to the include files in NodeCmd.cpp, should I correct this as well?

xmak avatar Apr 23 '20 06:04 xmak

Those are fairly standard 4.24 compile bugs (they changed include precision), and for sure I'll merge anything that helps improve the plugin :)

getnamo avatar Apr 23 '20 10:04 getnamo

I've made the quickfix, created pull request.

Btw, when I was testing the fix, I had to close Unreal Editor and open it again for changes in scriptHandler.js to be applied to the project. Is there a faster way to test it?

xmak avatar Apr 27 '20 08:04 xmak