Feature request: option for console
nw redirects console to devtool. This behavior disables simple inter-process communication through stdout.
An option for console would be really helpful to choice behaviour.
I think 'enable redirection/disable redirection/use both of redirection and terminal output' would be fine.
As advanced requests, integration with process.stdout would be more helpful and if stdin implemented, it will be really great!
@xylosper It would be more helpful to understand your request if you can provide usage scenarios in code.
@xylosper you could always just use process.stdout.write() directly, write a simple wrapper, or even copy the nodejs console implementation into your code
If you are using stdout for interprocess communication you'll want to write a wrapper anyways to have an identifiable format, since nwjs writes stuff to stdout too.
@ghostoy For instance, I want to do something like:
const spawn = require('child_process').spawn;
const child = spawn('nw', ['path/to/child/process']);
child.stdout.on('data', data => {
const result = parseDataFromChildProcess(data);
const feedback = doSomethingWithResult(result);
child.stdin.write(makeAnFeedbackMessage(feedback);
});
For now, there's nothing retrieved from child.stdout. All terminal output of child go to the devTool of child nw instance.
And, as already known, nw does not support stdin. But stdin support is not the main concern in this feature request.
@kiavashps
I've already tested process.stdout.write() but it didn't work for neither of devTool and terminal.
Here's an sample code for child process:
index.html
<html>
<head>
<script>
console.log('console.log');
process.stdout.write('process.stdout.write');
</script>
</head>
<body></body>
</html>
package.json
{
"main": "index.html",
"name": "test"
}
When I run this in terminal(windows cmd), I cannot get nothing in terminal and I can see only 'console.log' in console of devTools.
@xylosper interesting, it works for me on mac 10.11 and nwjs v0.15.4 what nwjs and os version are you using?
I can confirm this behavior on Windows 10 using NW.js 0.16.1.
This 3 year old issue seems related: https://github.com/nwjs/nw.js/issues/685
@kiavashps I've tested nwjs 0.15.4, 0.16.0 and 0.16.1 on Window 8.
@frankhale
I'm not sure. They're talking about --enable-logging but when I used it, it worked well, but I got tons of debugging message from chrome which is totally useless for my purpose.
Also, they just saying that stdout doesn't work. They didn't mention neither of which method they used to log to stdout, nor in which console(devTool or terminal) they want to see the log.
yeah, in my experience stdout doesn't work on Windows (while it works fine on other OSes). Only stderr works. Which is problematic for some loggings libraries (including https://github.com/visionmedia/debug)