[Tutor] What am I missing here?

Nathan Smith nathan-tech at hotmail.com
Fri Feb 11 21:38:58 EST 2022


Hi List,


I wrote a proof of concept program, it was supposed to be a more 
accessible command line for windows.

Essentially it was just supposed to be a pretty gui for command line.

To act as command line, I had:

handle=subprocess.Popen("c:\\windows\\System32\\cmd.exe", 
stderr=subprocess.PIPE, stdout=subprocess.PIPE, 
stdin=subprocess.PIPE,creationflags = subprocess.CREATE_NO_WINDOW,, 
universal_newlines=True)


Then I tthreaded while loops to read from stdout and stderr and put the 
contents into a text box, while anything entered into the other box got 
written to stdin and flushed

Such as:

line=get_line()

handle.stdin.write(line+"\n")

handle.stdin.flush()


And it works. Kind of.


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


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?


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?


Thanks in advance for any help..

Confused

-- 

Best Wishes,

Nathan Smith, BSC


My Website: https://nathantech.net




More information about the Tutor mailing list