Is there a way, in Linux, to make the electron executable copy or redirect output sent to its console to the shell console, i.e. when I run it from a terminal?
For instance, if I run, in a shell, electron foo.js, where foo.js contains simply console.log("foo"), I get the foo message echoed back to my terminal.
However, when I run a React app, the output of console.log is directed to the browser's console (as explained here).
Is there a way to copy/redirect the outputs sent to the browser Console, so that they will also be sent to the shell console? This can be very useful for some kinds of debugging (e.g. using grep and regexes).
Alternatively, if there are other methods than console.log that allow writing to the shell which created the browser process, that would also be helpful.
Edit: #0stone0 mentioned the difference between server code and client code; from the point of view of debugging, since I am running a local process, the browser could very well decide to copy its console output to stdout/stderr. I fail to see why technically Chromium could not do it; requiring an API or websockets for this use case seems excessive, but if that is indeed necessary (e.g. for security reasons), that is a valid answer for me.
I just found a way, thanks to this question:
Q: Does anyone know of a way to save the console.log output in Chrome to a file? Or how to copy the text out of the console?
A: Enable logging from the command line using the flags:
--enable-logging --v=1
I then combined it with the answer to this question to set the Chromium flag in my Electron app:
app.commandLine.appendSwitch('enable-logging');
And that is enough for me to get messages in my console, such as:
[1234:0328/3923.5981:INFO:CONSOLE(2)] "logging", source: file:///home/user/app/main.js
Related
Im trying to save curl result into a file so I can analize it later using other tools.
curl https://www.revolico.com/compra-venta/electrodomesticos/search.html?q=lavadora&order=date
the command works fine and I get the result on screen. The problem arises when I want to save it to a file. I have read related questions in stackoverflow and I think this one is a bit different.
When I use the command:
curl https://www.revolico.com/compra-venta/electrodomesticos/search.html?q=lavadora&order=date > testing.txt
Nothing is written into the file and the outputs once again goes to the screen.
I tried using the output choice
curl https://www.revolico.com/compra-venta/electrodomesticos/search.html?q=lavadora&order=date --ouput testing.txt
But curl says that doesnt recognize the command and prints the result to the screen. Same result using "-o".
I used curl in a localhost web server and everything worked ok. I think the difference resides in size because I also used on www.google.com and it worked just fine too. Did anyone run into the same problem before?
Place the options before the URL. Using —output is the best way, as it doesn’t clobber stdout. If this change still “doesn’t recognize the command”, maybe it is a really old or fake curl (like in PowerShell)? I usually run with -vv interactively, as it can sometimes show things like not following redirects (see/use -L to automatically follow) — https://linux.die.net/man/1/curl
So something like the following might be useful, to either fix the issue due to proper URL placement and ensuring to following redirects, or failing that, showing useful diagnostic information:
url=https://www.revolico.com/...
curl -vv -L --output testing.txt $url
When an app is run via Xcode the result of fputs("Hello World", stdout) appears in the Xcode console. Where does it go when Xcode is not attached? Does the answer change for Debug vs. Release builds? You would think that information such as this would be easy to obtain; surprisingly not.
Update: Hmmm, no answer. The reason that I used fputs as an example is that it explicitly references stdout. But swift's print() function also outputs to stdout. An alternate question might be: What reasons, beyond performance, are there for eliminating print() statements from release builds:
When a GUI app is running under MacOS anything written to the "standard output" is sent to the console, which in turn is written to the console log. The easiest way to view the log is to use the Console app found in Utilities.
As to your alternative question reducing what your app writes to the console avoids cluttering up the console log with useless stuff - just take a look and see the amount of non-useful stuff some apps dump out. As a possible metric, if you as app developer will never ask a user to report something your app has written to the console then your app should not write it there, i.e. don't litter!
I am running a script that tries to launch a browser (firefox) and load a URL from my home intranet's NAS - in order to close it down. This should run unattended. My first problem was getting the "çertificate not recognised" message from the browser, when I want this to run unattended, so I added an exception. Re-tried and then I got the "User / Password" dialogue. So I found a way to insert the credentials into the URL. That seemed to silence that dialogue, but now I get the following pop up - seemingly from the browser, which remains blank unless I Ok it:
I'm not sure what's generating it. The browser I guess, but it never does this when I access the URL manually. I tried turning off my Avast security in case it came from there. I tried fiddling with Windows (10) security, but still it persists. Any idea how to do this? Here is the .bat line that initiaties it:
run, C:\Program Files\Mozilla Firefox\firefox.exe
https://admin:mypassword#192.168.1.10/get_handler?PAGE=System&OUTER_TAB=tab_shutdown&INNER_TAB=NONE&shutdown_option1=1&command=poweroff&OPERATION=set
It might help to know the NAS responds to http, switching it to https, with it's own local certificate. Anyone any ideas on how to circumvent this? Thank you.
I confirmed that the dialog is indeed coming from Firefox, using Window Spy to click on it when it appeared. No idea why it should happen in response to a script and not to a live operator though: it does rather present the script with the sort of issues documented here.
After trying all sorts of techniques to try to either surpress it or Ok it, I found that nothing native to Windows would do the job. I eventually solved the problem by writing a script for Autohotkey, making an executable out of it for convenience, and calling that from my close down .bat file.
Is it possible to redirect the output of GWT.log() from the development console to a file? I need to debug a compiled GWT app and any logging or exception traces would be really nice.
GWT.log is compiled out, there is no way to get access to it when compiled to production.
On the other hand, GWT now has support for java.util.Logging, which can, when compiled in, send errors to the server for use however you want. It also can print these logging statements to a in-browser console, such as a popup or Firebug/Chrome Inspector. See http://code.google.com/webtoolkit/doc/latest/DevGuideLogging.html#Remote_Logging (and other sections on that page) for more details.
Keep in mind that unless you compile in full stack trace info, the exceptions will be very hard to read. See http://code.google.com/p/google-web-toolkit/wiki/WebModeExceptions#Emulated_Stack_Data for more info.
There is no way for a browser (without dev mode running) to write to a local file, for logging or other reasons. This is done for security reasons. Html5 might have support for some of these things, but they won't be supported in older browsers.
I installed a PostScript printer driver and have setup REDMON (redmonnt.dll) for redirecting postscript output to my program. In my rather simple c program I capture the data from STDIN and I am able to successfully save it into a .ps file. The file looks OK.
However, I want to start gsview.exe for viewing the file. If I call ShellExecute it fails in Windows 7 because of permission issues. It seems that my program is called under a different user account (LOCAL SERVICE). So I am looking for a way to run gsview.exe under a specific username (the user who initiated the print job) which is available to the program in a variable called REDMON_USER along with the SESSIONID as well.
Q: What are the minimum WinAPI calls required to start a program given a username and a sessionid?
Any code examples in C/C++, .NET would be very helpful.
EDIT: What I am trying accomplish is something very similar to redrunee (from redmonee). I don't want to use redrunee because it opens about a console window for a brief moment.
Note:
1) The program is called by the printer service as [LOCAL SERVICE] account.
2) The first parameter Username (REDMON_USER), in effect, points to the user currently looking at the screen
Look at CreateProcessAsUser.
Also look at CreateProcessWithLogonW and CreateProcess.
They are linked from the CreateProcessAsUser
EDIT In reply to comments by OP.
Follow advice from this thread.
I am copying this here verbatim, in case the original link stops working:
The same code works for us on Vista as
on XP, etc. The service is running as
the Local System.
use WTSGetActiveConsoleSessionId to get the ID of the current active
Windows session at the console (i.e.
the machine keyboard and display, as
opposed to WTS sessions).
use WTSQueryUserToken to get the token for that session.
use DuplicateTokenEx(hToken,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,
&hTokenDup) to duplicate that token.
use CreateEnvironmentBlock to create an environment that you will be
passing to the process.
use CreateProcessAsUser with the duplicated token and the created
environment. Actually, we use
CreateProcessAsUserW, since the A
version had some sort of bug on some
older systems.
Don't forget to CloseHandle on the various tokens, etc, and to
DestroyEnvironmentBlock the
environment.
Thank you efratian.
PS. Oh joy of Windows programming, did not do it for quite a while. Now I remember why. The only thing that is close or even worse documented is OpenSSH programming.
The documentation describes the "Run as User" feature, which seems to be exactly what you want:
Run as User is intended for launching a GUI program such as GSview locally via RedRun.