4

I've got a standard electron app (based off of electron-prebuilt) that ought to be writing to std out with the following command: (in my project's main.js)

process.stdout.write('stdout write test')

when I launch the app from powershell and redirect the output to a txt file, I see the string displayed in the terminal window as expected:

> .\App.exe > log.txt

stdout write test

but when I open log.txt it's a blank file. what am I missing?

edit: to clarify Ansgar Wiechers' correct answer: in the windows command prompt, I needed to run the following command:

set ELECTRON_NO_ATTACH_CONSOLE=true

This results in console.log and process.stdout.write being directed to windows' stdout stream.

matt lohkamp
  • 2,174
  • 3
  • 28
  • 47
  • Have you tried to [Invoke the command](http://stackoverflow.com/questions/35588062/getting-stdout-to-appear-on-console-with-powershell-invoke-command-and-process) – lloyd Jan 24 '17 at 02:46

1 Answers1

3

If you run .\App.exe > log.txt and you can see the output string in the console it means that the string is not being written to STDOUT (the Success output stream in PowerShell terms) in the first place.

Apparently the Electron developers decided to attach stdout directly to the console instead of actual STDOUT (see issue #4552). If I understand the discussion there correctly you can set the environment variable ELECTRON_NO_ATTACH_CONSOLE to avoid this behavior.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • ah, I had tried setting that env var in powershell - electron wasn't picking up on that, but setting it from cmd works perfectly. thanks! – matt lohkamp Jan 25 '17 at 04:15
  • 1
    Untested, but noramlly setting `$env:ELECTRON_NO_ATTACH_CONSOLE='true'` in PowerShell should do the same as `set ELECTRON_NO_ATTACH_CONSOLE=true` in CMD. – Ansgar Wiechers Jan 25 '17 at 09:12
  • Yeah, I realized that `set` in powershell is just an alias for `Set-Variable`, which isn't actually the variable I want. – matt lohkamp Jan 27 '17 at 01:06