-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Console error then open some extension file. #495
Comments
Sit beside me and hear my sad story. There are apps that talk to the the outside world in text (for example, git). When you run them, either the console of the parent process is used (if any), or a new one is created ("the scary black window"). There are programs that talk to the outside world in various GUI controls (for example, photoshop or wireshark). They do not need the console by design, it only scares the users, so such apps are linked in a special way and when you run them, this scary black window is not created. And there are libraries that usually don't talk to the outside world at all. From time to time developers want to show various debug messages for various reasons. Once upon a time, probably after weeks of meditation, one software guru discovered that he can attach to the console of the parent process and drop his stuff right into it! Just imagine how convenient it is - laypeople, who run his piece of work from Windows Explorer, won't notice anything suspicious, because it does not have a console, but he can neatly run it from cmd.exe and see everything. Awesome. Another day another specimen discovered that in the library code you can just write to stdout without bothering with anything at all. If there's any console attached to the process, the text will be visible. And if no, then not. Amazing. Gurus share their wisdom on stackoverflow.com and the sacred knowledge goes to the masses. And the fact that the console might not even belong to them in the first place, and can be actively used by something else - meh, who cares. In other words:
Obviously, we can't do anything about it. |
Uh-oh. Спасибо, Алекc, it's quite a full explanation. But i can't agree we have no method to avoid this behavior:
PS: I also remember other bit annoying (and connected) issue - if i have a scroll bar into Far console window (f.e. for history), close panels by CTRL+O and scroll it back, then press CTRL-O again to show it back - i still stay at current scrolling position, with panels at the end of console. Is it possible to scroll to the end in this case, make panels visible without manual scrolling? |
There are workarounds of course, it's just that my comment got too long already. By "we can't do anything" I mean "anything remotely reasonable, that can be added to the code and won't break something else".
Yes, anything that would break the parent-child process link will do.
What about bat files, python scripts etc.?
It might help if the offending app litters once. What if it does so every second? Actually, everything you need is already there, you just need to set it up manually:
This way far will spawn cmd that will spawn wireshark and quit.
Just press Esc. |
You are right, it will need to separate executable and extension. Ok, forget about it.
Well... Better than nothing. It can also help in other situations (like moving windows to the different DPI screen, it made a mess sometimes right now).
I think also
Thank you for the hint. But did it reasonable to keep scrolling outside panel then user issue "show me panels" command? PS: Ok, the situation is clear for me, and for you as well. Please, think a bit about my points, i'm close this issue. |
Please raise a new issue for this.
I'll think about it. |
You may create small intermediate GUI application to start needed GUI applications. So that sacred hack will not find your console (unless they're really persistent and will try to go |
@elfmz The question is to decide what extension need this kind of start and what didn't, and it will interfere with output. |
It must be used only for applications that have win32 type specified in PE header. |
It's a mess here as well. Application type is wrong sometimes. |
We do not know beforehand whether a given command spawns a GUI or a CUI application. We just run it and get a process handle, which we then inspect, find out its subsystem and act accordingly. |
Then, if CreateProcess is used - may be this may help - https://scorpiosoftware.net/2021/01/10/parent-process-vs-creator-process/ - it allows to specify arbitrary parent for launched process. Unfortunately documentation (https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute) doesn't tell anything how it will affect behavior of console processes - if they will use console of that surrogate parent or still will run within console of actual parent, so its up to checking on practice. But if it will not affect console inheritance - then you may run simple win32 app and just assign it as parent for all processes you're starting. |
Thank you, it's a quite interesting trick. A GUI app that invokes Unfortunately, all console processes spawned this way immediately fail with STATUS_DLL_INIT_FAILED, supposedly more magic is required for such initialisation. And, unfortunately, this won't help in this particular case at all, since CreateProcess doesn't work with file associations and they are handled by ShellExecuteEx. |
And, obviously, the parent-child relation is a good thing and a useful concept in general, e.g. finding a specific instance is much easier in a hierarchical structure than in a flat list, especially if you have hundreds of processes. I don't think we should break it for everything and everyone only because a few specific apps do mental things. Again, this is not a Far-only issue, all console processes are affected. The user might start wireshark from a cmd session and then immediately start doing something else in the same session and that debug spam could break their workflow. |
I suspect it will be hard to convince that its a bug as MS added this as explicit documented flag for AttachConsole -ATTACH_PARENT_PROCESS. And i dont remember this flag from times i was Windows dev, likely it was added recently - that guru must be working at MS. |
The existence of an API doesn't yet imply that it can be carelessly used for arbitrary actions. DeleteFile and TerminateProcess also exist and fully documented, does that mean that an app can delete random files or kill random processes if there's non enough disk space or memory for it? |
One possible solution that could be used with
|
There's another argument, if "common sense" is not enough:
|
Alternatively, if such process attached to console and writing to it - it can be considered as console app with GUI. You may detect such situation by checking if spawned process appeared in GetConsoleProcessList and.. do not return until it finish (or disappear from GetConsoleProcessList). Not sure whats better though - see random console garbage or this. Also, race possible if that process will attach after you check for that (but may guess that this will not happen since ShellExecute does WaitForInpuIdle - likely spawned process will attach console before starting to pump events. |
Yes, exactly - random GUI apps blocking the execution would cause even more raised eyebrows and bug reports. |
Anyway, adding intermediate app for Shift+Enter can be useful at least as workaround for such cases. As i understand currently there is no workaround except yelling to authors of nasty app? |
I wonder how many such nasty apps are there? FAR can nicely handle majority of cases. There are few corner cases. Maybe instead of having FAR authors to handle those cases and run the risk of breaking some other mainstream cases, the avid users of those applications can apply targeted workaround? Such workaround may be promoted to a macro or a plugin if it is good enough. Then, all users of such nasty apps would enjoy running them seamlessly from FAR, while other users will not pay for overhead on launching every command? |
I suppose one can write a macro for Shift+Enter that would take the command line text and pass it to any desirable external launcher, or at least to cmd with the "start" prefix. Of course, it would've been nice to have an out-of-the-box solution at least for Shift+Enter, which is a slightly less convoluted case since we don't need to care about GUI/CUI at all. It is easy to come up with various workarounds for specific cases, but much harder to provide a robust generic solution. I see this issue from time to time since 2010 or so, think about it every time but can't find a silver bullet. And again, this is a bug and it should be fixed. Here Far is not even mentioned, yet people are suffering from the same issue in pure cmd because some electron dev was way too smart. |
Far Manager version
3.0.5888.0 x64
OS version
10.0.19044.1387
Other software
(maybe) WireShark.
Steps to reproduce
Expected behavior
File opened in Wireshark.
Actual behavior
File opened in Wireshark, but also console error in Far, followed by visual mess (panel position shifts up by console error text size (1-2 rows)).
The text was updated successfully, but these errors were encountered: