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.
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.
Related
I'd like to run a program as root that can intercept other's program stderr and stdout.
For example, say I start a nodejs server and somehow there's an error (with logs printed to stderr), if my program is running, I would like it to intercept this error.
Is that possible ? How should I do ?
Also, an idea that came to my mind was to replace nodejs binary by another one that starts nodejs and redirect stderr to a custom file. but I think it's too messy and I hope there's better ways to do that.
If you can control how nodejs is called you can redirect stderr to a named pipe and then read the named pipe from another command like this:
mkfifo /tmp/nodejs.stderr
nodejs 2>/tmp/nodejs.stderr
Then in some other shell type:
grep "Error Pattern" </tmp/nodejs.stderr
If you can't control how nodejs is called, then you can create a shell script to wrap those commands and call the shell script wherever nodejs is called.
I trigger a bash script from Windows command prompt.
postCloneSetup.sh
It opens another window and then returns. The window it spawned stays open and logs output text.
I want to capture the output from the spawned window and return that to the Windows command prompt.
I would prefer to use something like
$(postCloneSetup.sh) // Linux for capturing output to current context
for the Windows command prompt.
I'd prefer not to modify postCloneSetup.sh. I know I could have it write out to a file with
exec &> postCloneSetupLog.log
but then I must wait and manually run
type postCloneSetupLog.log
to see the output in the console. This is not possible for integrating into a CI engine, which is my goal.
How can I capture the output from the spawned console in one command?
I've downloaded and "installed" VSCode for Linux. I have placed the app in /home/Christian/Apps/VSCode/ and symlinked the executable to /usr/bin/code.
When I use this method to start Code it hijacks the terminal (expected I guess) and also dumps a lot of STDERR stuff at the same time.
If I redirect STDERR to a file, for example like
code 2> ~/.logs/VSCode-`date +%Y%m%d%H%M%S.log` &
Then I can get it to give me back my prompt, and it's silent (logging everything to the filename I gave it).
I was thinking of making this an alias, but then I realized I can't inject arguments ($1 $2 $3) in an alias. And I usually want to start code with code filename.js or code ..
What is the correct way to launch an application like this "in the background"?
Instead of making a symlink to the executable, create a bash script like this:
#!/bin/bash
/path/to/VSCode/Code "$#" 2>/dev/null &
How can I redirect everything what is displayed in console to a file?
I mean for example, i call some function, this function display something on console (no metter if it is console.log or process.stdout.write)?
Thanks for help!
While not strictly a Node.js answer, you could achieve this at the shell level. For example if you are using bash, you could redirect both standard output and error stream to a file using the following
#!/bin/bash
node app.js &> output.log
Check out also tee command for simultaneous output to both file and screen.
I'm working on a project where rather than using command line arguments I am supposed to just pipe a file to stdin and pipe output to another file.
ie I need to run something like:
./program < infile.txt > outfile.txt
Is there a way to specify to Eclipse this is the command I want when it is run?
I am running the Eclipse-C/C++ environment.
After using Eclipse for some time, it seems like there is not a straightforward way of doing this. I've resorted to just adding debug code to specify a file and then declare it as an input stream.