Windows 10: command window does not close, but closes in Windows 7 - windows

i'm using windows 10 and trying to start an exe in diffrent folders sequentially. The idea is to use popen from subprocess and wait for the process to finish. The problem is, that the window does only close if I click on it or hit a key. On a windows 7 machine however the window is closing and subprocess.wait() finishes.
import os
import subprocess
for path in ["C:\tmp\", "C:\tmp2\"]:
os.chdir(path)
mywindow = subprocess.Popen(["my.exe",
#stdin=subprocess.PIPE,
#stdout=subprocess.PIPE,
#stderr=subprocess.PIPE,
#shell=True,
creationflags=subprocess.CREATE_NEW_CONSOLE,
env=dict(os.environ, **{"test":"AUTO"}))
mywindow.wait()
I used creationflags=subprocess.CREATE_NEW_CONSOLE, because I need to be able to start my.exe multiple times and be able to read the output on another console. But in some cases I want to wait for my process to end.
Update:
After eryksuns comment I'm pretty sure that this more of a windows problem than a python one.
On Windows 7 "my.exe" exits and wait() returns afterwards. On windows 10 however, I have to click somewhere on the screen or press any key, in order to close the console window "my.exe" opens. Afterwards the wait()returns. Disabeling the cmd quick edit mode had no effect.

Related

Close Unwanted Mac Terminal Windows En-masse

As a system admin, I write/test/run a ton of shell scripts (typically from BBEdit). I rely on the BBEdit “Run in Terminal” drop-down menu a lot to quickly test run a script.
As a result, I end up with a ton of 'dead' (unwanted/expired) Terminal windows (i.e. executed script windows with “[Process completed]" displayed at the bottom).
Does anyone have a suggestion for how to clean-up all of these dead Terminal windows em-masse?
I can't blindly close ALL windows (or quit Teminal.app) because I have current SSH sessions running and other tasks in-progress. I only want to close the Terminal windows that have been executed via BBEdit and display '“[Process completed]'.
I can't set the Apple Terminal.app preference to do this for me (Terminal -> Preferences -> Settings -> Shell -> When the shell exits) because I generally want to examine the output returned before closing for QA purposes.
My goal is to manually run a script/command from time to time to clean-up all the Terminal windows on-demand as needed. Once I have a ton of confusing dead windows that I dont need Ill run it and then continue working in BBEdit as needed.
After a few hours of writing/troubleshooting/editing a script (or multiple scripts) I end up with dozens of dead Terminal windows - of which I manually close with a click and a Command + W. This gets tedious of course.
I have played around in AppleScript for something to bind to a shortcut or widget, but haven't found a solution as of yet.
Simple commands such as
tell application "Terminal" to close (get window 1)
aren't too helpful because I havent been able to determine which windows have an inactive state and which do not.
Thoughts? Any suggestions are appreciated!
Every "window" object in Terminal has a property named "processes", which is a list of the active processes for that window.
If the "processes" list is empty (in AppleScript terms, processes = {}), then you can safely close the window.
Therefore, an AppleScript like this should work:
tell application "Terminal"
set windowsICanClose to (every window whose processes = {})
repeat with windowToClose in windowsICanClose
close windowToClose
end repeat
end tell
You can save that as a script, put it in BBEdit's "Scripts" folder, assign it a keyboard equivalent if you like, and that should do the job.
It's very simple:
tell application "Terminal" to close (every window whose processes = {})
This will close every window of Terminal that has: [Process completed]
Just to be clear.. If e.g. you have a Terminal window open with multiple tabs, then tell application "Terminal" to close (every window whose processes = {}) only closes the tabs that have [Process completed] and not any other tab in that window. The window is only closed if the only tab of that window contains [Process completed]. That is to say, that is the result as tested under macOS High Sierra anyway.

Managing windows when local SAS session starts

When a SAS session starts, there are 5 windows. (Result Viewer, Explorer, Log, Editor, Output).
My desired state is when the session starts:
No result viewer
No output window
No default explorer window
The useable explorer window default open(to clarify this i attached a picture)
Good/Bad explorer window
Enchanced editor open
Log window open
So there will be 3 windows opened at session start, and i would like to resize them into 3 columns.
What i got so far:
I know the task can be done, because i was able to do this on my working computer. Unfortunately they reinstalled my windows without a word, and i lost my setup. And i did not have my autoexec/sasv9cfg file backuped. :(
I can close the output window with dm listing off command in my autoexec.
I can resize the 3 windows if i have them, with dm wdef command as well.
My biggest issue is i cant find again a DM/ODS or any kind of command, which closes the Result Viewer, and the original Explorer, and opens the normal/usable Explorer. In my faded memories i needed only 1 DM/ODS/sth command to achieve these 3 steps at once. Of course, if we can find a solution in more steps, thats also completely fine.
Big thx for any kind of help
You do not want the DMSEXP docked windows (which includes ODS Results tab) at session start up. The only way to do this programmatically is to specify the SAS system option -nodmsexp in the sas.exe command line or config.sys.
So, on my system, I set the target command on my SAS icon to be:
"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe"
-CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg"
-NODMSEXP
Tweak the SAS DM session window states by placing this code in your autoexec.sas
dm 'dmsexp;tree on;next;listing off;tile vert' ;
You can also fiddle around with your session start up using the system options:
initstmt=
initcmd

Press enter to close a window in Batch

I'm playing a game and alongside the game .exe I also run another .exe that runs a personal program I'm developing (it records information that I can then monitor outside the game.)
One of the .exe's opens a cmd window, which I'd then like to immediately close at the end of the .bat.
Pressing enter manually will close the window, however, I don't know how to automate the enter keypress.
All I want to do is automate the pressing of the enter key after both the exes have been launched.
Should be simple to do I guess! but looked around for a while and can't find a solution.
Thanks.
the code for my very very basic batch:
start "" "E:\World of Warcraft\Wow-64.exe"
start "" "C:\Users\Kek\Desktop\New folder\DocumentAll.exe"

Command prompt gets stuck and continues on enter key press

Does anyone come across a scenario when the command prompt is running a process and then it gets stuck and the process is also sleeping.
Then when we press Enter key in the cmd window the process continues.
Is there any way to avoid this?
or can this be handled??
The other answers are wrong! The Windows console has a separate mode called "mark mode" for selecting text. In that mode the screen will be frozen, texts will go into the buffer and if the buffer is full the running process will be blocked
If quick edit mode is enabled (by default it's disabled in older Windows but enabled in Windows 10) then clicking inside the console window will activate mark mode and result in what you observed
It's very easy to accidentally click the console and stop the command. When you press Enter or Esc the selected text will be copied to clipboard and mark mode will be exited, therefore the process will run again. Priority is absolutely irrelevant here because if the buffer is full then the process is blocked forever until you exit mark mode, regardless of the priority. The console does nothing to change the priority when there are some inputs. Try opening an app that outputs a lot of data in the highest priority and click the console, the app will still be blocked indefinitely even if the CPU is in idle
Here's an example of QuickEdit mode setting in Windows 8 console:
To fix this you can disable QuickEdit mode if you don't need it. In this case copying will be more troublesome because you must open the context menu, select Edit > Mark. You can also disable QuickEdit mode by setting ENABLE_QUICK_EDIT_MODE with SetConsoleMode() if you're writing your own console application
See also
How and why does QuickEdit mode in Command Prompt freeze applications?
What does it do exactly if I click in the window of cmd?
Turn off Windows 10 console "Mark" mode from my application
If other processes are sucking all the cycles and have a higher prio, then your process might be stopped. A user input might just give it a prio boost, so it starts again. See Microsoft Docs at https://learn.microsoft.com/en-us/windows/win32/procthread/priority-boosts for more information.
It happened to me today while executing a batch file that includes TFSBuild.
I already received email notification from TFSBuild that it is successful, but somehow the batch file did not proceed to the next line.
I waited 1 hour.
I pressed Enter, Mark for Edit etc. but none of that worked.
Then I hit Ctrl+C to try to terminate the batch file.
When asked if I want to terminate, i entered N.
Weirdly enough, the batch file continued after that.

How can I see which processes/programs are sending/recieving data over internet in XP?

Is it possible to write a script to see which processes/programs are sending/receiving data over the internet in Windows XP? I have full administrator rights and I want to find a way to monitor data exchange on my machine without installing any additional software.
Step One: Windows XP
Open up the Run box by pressing the Windows key and R at the same time.
Put in CMD and press OK. The command prompt window will open up:
Step Two
In your open Command Prompt window, enter the following:
netstat -b 5 > activity.txt
and hit enter. (Note: to paste something into Command Prompt, you'll need to right click and click paste.)
If you forgot to run the prompt as an administrator (like I did in the screenshots above), just redo step one You can tell when it's running as administrator because instead of saying C:\Users\Username it says C:\Windows\system32.
If you've pasted the code right, a blinking cursor will... blink.
After a few minutes, press Ctrl+C. That'll stop the command.
Now type in command prompt activity.txt to open the log:
When you press Enter, your default text editor-probably Notepad-will open:
Now, scroll through the lists. You'll see that it's mostly your browser-but some times, there are programs like Google Talk's webcam program installed that call home even when you aren't using them.
Now that you've found any and all culprits that are programs accessing the internet (with and without your knowledge), you can either close them from the Task Manager or even uninstall them.

Resources