You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Can't get the output of dir command on Windows. Either a timeout error is raised or the output is different from the output as cmd.exe (without space warp between columns).
To Reproduce
importwexpectdefrun_cmd():
# Start cmd.exe processcmd=wexpect.spawn("cmd.exe")
# Display the initial promptcmd.expect(">")
print(cmd.before+">", end="")
whileTrue:
# Read user inputuser_input=input()
# Exit loop if user types "exit"ifuser_input.lower() =="exit":
cmd.sendline("exit")
break# Send the user input to cmd.execmd.sendline(user_input+" && (echo commandend1 && echo commandend2) || (echo commandend1 && echo commandend2)")
# Wait for the command to complete and print its outputcmd.expect(r"(commandend1 \r\ncommandend2\r\n\r\n(?:[^\\]+\\)*[^\\]*>)")
# Remove the first line of command output (user input)print("\r\n".join(cmd.before.split("\r\n")[1:]))
prompt=cmd.after.replace("commandend1 \r\ncommandend2\r\n\r\n", "")
print(prompt, end="")
if__name__=="__main__":
run_cmd()
Expected behavior
Expected output (supposed to be exactly the same output as cmd.exe):
Microsoft Windows [Version 10.0.22631.3810]
(c) Microsoft Corporation. All rights reserved.
C:\Users\vIIr>dir
Volume in drive C is Acer
Volume Serial Number is C226-92AB
Directory of C:\Users\vIIr
2024/06/30 下午 07:15 <DIR> .
2023/10/07 下午 11:43 <DIR> ..
2024/03/27 下午 08:43 <DIR> .arduino-create
2024/03/28 下午 01:23 <DIR> .arduinoIDE
...
2024/05/23 上午 10:33 <DIR> Pictures
2023/12/03 上午 10:21 <DIR> Saved Games
2023/10/07 下午 11:11 <DIR> Searches
2023/10/08 下午 04:16 <DIR> Tracing
2024/06/21 下午 07:00 <DIR> Videos
16 File(s) 34,059,527 bytes
27 Dir(s) 22,039,977,984 bytes free
C:\Users\vIIr>
Environment:
[windows version] Windows 11 Pro 23H2
[Python version] 3.10.6
[wexpect version] 4.0.0
The text was updated successfully, but these errors were encountered:
I tried repr() and found that there was no \r\n or \n in the raw output of the child process (cmd), which I thought was a bug in wexpect's way of reading the output. Or should I try to update my python as my python version is 3.10.6?
Describe the bug
Can't get the output of
dir
command on Windows. Either a timeout error is raised or the output is different from the output ascmd.exe
(without space warp between columns).To Reproduce
Expected behavior
Expected output (supposed to be exactly the same output as
cmd.exe
):Environment:
The text was updated successfully, but these errors were encountered: