[Tutor] What am I missing here?

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Feb 12 12:49:38 EST 2022


On Sat, 12 Feb 2022 02:38:58 +0000, Nathan Smith <nathan-tech at hotmail.com>
declaimed the following:


>Two places it does not work:
>
>1 In command line, it always puts the current directory at the end of 
>the execution of a command, eg
>
>dir:
>
>output
>
>c:/users/user/documents
>
>echo hi
>
>hi
>
>c:/users/user/documents

	Please cut&paste the actual text. Windows command shells use \ for path
separators (the internal API doesn't care) -- and the prompt concludes with
a > marker

Microsoft Windows [Version 10.0.19041.1415]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Wulfraed>echo help me
help me

C:\Users\Wulfraed>

>
>
>In my GUI that path does not always show, but I'm assuming that's just 
>because it doesn't throw in an extra empty blank line or some such?
>
	The I/O system, when not connected to a terminal/console, typically
doesn't flush the output until a new-line is emitted; it expects the next
command to be input on the same "line" -- so the prompt may not be
available on your line-oriented read operation.

>
>More to the point though, if I run python from my gui, it just doesn't 
>show anything. No output, nothing. It's like it disconnects.
>
>Am I missing something?
>
>Even if the python command puts us into it's own command line, surely 
>subprocess's stdout and stderr should capture the output?
>
	I believe it is possible for processes to "attach" to a "console" which
is the window itself, not the default shell process within it. I
hypothesize that stdin/stdout/stderr are tied to the process, not to the
console.

https://docs.microsoft.com/en-us/windows/console/attaching-to-a-console
https://docs.microsoft.com/en-us/windows/console/attachconsole
"""
This function is primarily useful to applications that were linked with
/SUBSYSTEM:WINDOWS, which implies to the operating system that a console is
not needed before entering the program's main method. In that instance, the
standard handles retrieved with GetStdHandle will likely be invalid on
startup until AttachConsole is called. The exception to this is if the
application is launched with handle inheritance by its parent process.
"""
	Yes -- normally sub-processes started from a console process do inherit
the streams... but nothing says the sub-process has to use them <G>

https://docs.microsoft.com/en-us/windows/console/allocconsole
"""
This function is primarily used by a graphical user interface (GUI)
application to create a console window. GUI applications are initialized
without a console. Console applications are initialized with a console,
unless they are created as detached processes (by calling the CreateProcess
function with the DETACHED_PROCESS flag).
"""

	Since running a "console" (*.py) script by double-clicking results in a
console window being created to display output, I suspect the interpreter
starts up in a "no console" mode, and then determines if it can attach or
needs to allocate... "GUI" (*.pyw) scripts aren't supposed to have a
console at all.


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list