Using std::process::Command with windows_subsystem="windows" causes console flash/popup - rust

OK, here is my situation:
I'm making a program with a GUI in rust and I don't want to show the console window to the user.
The easy solution for this is the flag (don't know if that's the actual name for those things) #![windows_subsystem = "windows"]. It works great, the console is gone. Buuut.. The std::process::Command struct is unusable because it flashes a cmd window and not actually runs the command.
So if I have a code like this, I wont be able to use it. (But i need it)
#![windows_subsystem = "windows"]
use std::process::Command;
fn main() {
// GUI stuff that at some point uses the Command like below
Command::new("runas").args(&["/user:MY-COMPANY\\Administrator", "/savecred", path]).spawn().expect("Couldnt start Installer");
}
Does anybody have any idea how I can hide the console window but still be able to use the Command?

An easy workaround for this issue is conhost.
You can use Command::new("conhost").arg("YourCommand")

Came here. Couldn't figure it out either. This is so obscure and nowhere else is there any listed solution. That conhost workaround didn't fix it at all sadly.
Anyways, here's the solution after I finally figured it out.
Import CommandExt on windows from the std library, then set command.creation_flags(CREATE_NO_WINDOW) (you can find the CREATE_NO_WINDOW constant in windows-rs or winapi)
I really don't suggest using the constant manually, but here is the value anyways:
const CREATE_NO_WINDOW: u32 = 134217728u32; (or 0x08000000)
I would like to correct something though
It does actually run the command. It just also flashes the window while doing it. But of course, with the solution above, window flashing is now gone
Here's a list of all of the process creation flags

Related

Why won't my one simple custom user Python snippet '__init__' appear in IntelliSense?

I've spent the last two hours trying to figure this out, but nothing I've found online helps. Either all search results I've found were severely outdated, not relevant to my problem, or didn't work.
I am a complete beginner to Python, so please try to make your suggestions/solutions/answers understandable enough for me (i.e. draw them in crayon if you must.:)) I want the init method to not autocomplete all of this:
__init__(self, *groups: _Group) -> None:
super().__init__(*groups)
I want it to simply autocomplete as "init()" and that's it, nice and clean for what I'm currently doing.
Searching around, looking at other python snippet extension files, and even using a snippet generator, I've
found that this should be the code that I should use:
"__init__ method":
{
"prefix": "__init__",
"body": ["__init__($0)"],
"description": "New __init__ method"
}
I've created a global.code-snippets file and even a python.json file with Configure User Snippets, both of which are located in C:\Users<myusername>\AppData\Roaming\Code\User\snippets. However, it does not show up when I type out init, instead I still get the default suggestions:
Default init suggestions
What am I missing? I didn't think this would be so difficult.
I've looked at https://code.visualstudio.com/docs/editor/userdefinedsnippets, I've tried https://snippet-generator.app/, I've checked out other Python snippet extensions to see how they were written out.
A bit more digging around and using different keyword searches this morning brought me to IntelliSense in Visual Studio Code, and 3/4 of the way down there was Suggestion selection which said to use the editor.suggestSelection setting. Turns out it was disabled. Once I enabled it, both my python.json and global.code-snippet suggestions showed up.

How to force reimport of texture in godot?

I have a sample.png file which is being changed outside godot
and after it's modified, godot recives a signal and when that signal is received
I want that specific sample.png file to be reimported
I tried this answer but I want to reimport in my script itself not create a plugin for it
(atleast that's what I'm assuming it does)
I also tried this from the documents but I'm not sure how to use it exactly
EditorFileSystem.update_file("res://Assets/sample.png")
so how do I achieve the desired result?
The class EditorFileSystem is intended for plugins.
You would call get_editor_interface() from an EditorPlugin (which would be where you would be writing code if you were making a plugin). And that gives you an EditorInterface object, on which you can call get_resource_filesystem() which gives you an EditorFileSystem object.
So the intended use is something like this:
extends EditorPlugin
func example() -> void:
var editor_file_system := get_editor_interface().get_resource_filesystem()
editor_file_system.scan_sources()
# editor_file_system.update_file("res://icon.png")
By the way, EditorInterface also has a filesystem_changed signal. Although I don't know how reliable it is.
Usually you don't have to do that. When you restore the Godot window, it will scan for changes in the project folder. So you might minimize Godot while you are working on something else and when you bring the Godot window back it will pick on the changes.
In practice, the only situations when I had to use scan or scan_sources was when I had a tool script that write a resource file which should be imported, and I wanted it to reflect right away.
Instead of making a custom plugin, I'll remind you that form a tool script (as long as it is running in the editor) you can simply create an EditorPlugin object. For example:
var ep = EditorPlugin.new()
ep.get_editor_interface().get_resource_filesystem().scan()
ep.free()
I had also shared this example in another answer I wrote for you a while back here, it is under the title "About saving resources from tool scripts".

How to get Flow type checker to detect changes in my files?

So Flow only works correctly the first time I run it, and then I have to restart my computer before it'll work correctly again.
Specifically, the problem I'm seeing is that we are using the Flow language to add type annotations to our JS code. Our linter script is setup to run flow type checking among other things. However, when I fix an issue in my code and then rerun the linter script, it still comes back with the exact same errors... BUT when it shows the piece of code where the error is supposed to be, it actually shows my updated code that's fixed.
So as an example, I had a file I copied into the project, that I didn't think I really needed, but maybe I would. So I copied it in just in case. Well then it came up with a bunch of linter errors, so I decided to just delete the file since I didn't really need it. So then I run "yarn lint --fix" again, but it's still complaining about that file, EVEN THOUGH THE FILE DOESN"T EXIST! Now interestingly, where the linter output is supposed to show the code for those errors it's just blank.
Or another example, let's say I had a couple of functions in my code:
100: function foo() {}
...
150: function bar() {}
And foo has a lot of errors because it was some throw away code I don't need anymore and so I just delete it. So the new code looks like:
100: function bar() {}
Well I rerun the linter and get an error like:
Error ------------------------ function foo has incorrect
something...blah blah
src/.../file.js
100| function bar() {}
I also tested this out on a coworker's machine and they got the same behavior that I did. So it's not something specific to my machine, although it could be specific to our project?
Note: There doesn't appear to be a tag for Flow, but I couldn't post without including at least one tag, so I used flowlang even though that's actually a different language :-( I'm assuming that anyone looking for flow would also use that tag since it's the closest.
The first time you launch Flow it starts up a background process that is then used for subsequent type checking. Unfortunately this background process is extremely slow, and buggy to boot. In linux you can run:
killall flow
To stop the background process. Then if you rerun the flow type checker, it will actually see all your latest changes.

Initiate "Sys" object in vbs

i'm trying to do some stuff in vbscript, and i have to take a screenshot of the screen. I don't want to use an external executable (Auto Screenshot using VBS).
I find a vbs which can be nice (how to take screenshot by vbscript?) but when i use this, it use an object (Sys), but i don't know how to create it.
I find some resources here, but i really don't know how to initiate the object "Sys", apparently it's like already "in" the vbscript, but it doesn't works for me.
I tried some stuff (Set Sys = CreateObject("System") or things like that, but nothing works :(
I hope you'll find something ^^
The question you've referenced looks like a low-quality question. The references to "Sys" that you see appear to be in a product called TestComplete. See How to capture a screenshot using VBScript in TestComplete? You'd need to acquire and install TestComplete to use it, or find another program to capture screenshots instead.

Can I alter Python source code while executing?

What I mean by this is:
I have a program. The end user is currently using it. I submit a new piece of source code and expect it to run as if it were always there?
I can't find an answer that specifically answers the point.
I'd like to be able to say, "extend" or add new features (rather than fix something that's already there on the fly) to the program without requiring a termination of the program (eg. Restart or exit).
Yes, you can definitely do that in python.
Although, it opens a security hole, so be very careful.
You can easily do this by setting up a "loader" class that can collect the source code you want it to use and then call the exec builtin function, just pass some python source code in and it will be evaluated.
Check the package
http://opensourcehacker.com/2011/11/08/sauna-reload-the-most-awesomely-named-python-package-ever/ . It allows to overcome certain raw edges of plain exec. Also it may be worth to check Dynamically reload a class definition in Python

Resources