May-04-2019, 02:58 AM
A simple code to call the Windows OS "dir" command:
b' Volume in drive C has no label.\r\n Volume Serial Number is 9999-9999\r\n\r\n Directory of C:\\Users\\ADMIN\\mypythonscripts\r\n\r\n05/03/2019 06:56 PM <DIR> .\r\n05/03/2019 06:56 PM <DIR> ..\r\n05/03/2019 07:46 PM 151 dir_test.py\r\n05/03/2019 04:56 PM 1,766 drmscript.py\r\n04/30/2019 06:39 AM 59 pw.bat\r\n04/30/2019 06:18 AM 600 pw.py\r\n 4 File(s) 2,576 bytes\r\n 2 Dir(s) 6,978,486,272 bytes free\r\n'
When I expected:
Volume in drive C has no label.
Volume Serial Number is 9999-9999
Directory of C:\Users\ADMIN\mypythonscripts
05/03/2019 06:56 PM <DIR> .
05/03/2019 06:56 PM <DIR> ..
05/03/2019 07:24 PM 142 dir_test.py
05/03/2019 04:56 PM 1,766 drmscript.py
04/30/2019 06:39 AM 59 pw.bat
04/30/2019 06:18 AM 600 pw.py
4 File(s) 2,567 bytes
2 Dir(s) 6,978,912,256 bytes free
What am I doing wrong?
import subprocess output = subprocess.run('dir',stdout=subprocess.PIPE,shell=True) print(output.stdout)Is printing this:
b' Volume in drive C has no label.\r\n Volume Serial Number is 9999-9999\r\n\r\n Directory of C:\\Users\\ADMIN\\mypythonscripts\r\n\r\n05/03/2019 06:56 PM <DIR> .\r\n05/03/2019 06:56 PM <DIR> ..\r\n05/03/2019 07:46 PM 151 dir_test.py\r\n05/03/2019 04:56 PM 1,766 drmscript.py\r\n04/30/2019 06:39 AM 59 pw.bat\r\n04/30/2019 06:18 AM 600 pw.py\r\n 4 File(s) 2,576 bytes\r\n 2 Dir(s) 6,978,486,272 bytes free\r\n'
When I expected:
Volume in drive C has no label.
Volume Serial Number is 9999-9999
Directory of C:\Users\ADMIN\mypythonscripts
05/03/2019 06:56 PM <DIR> .
05/03/2019 06:56 PM <DIR> ..
05/03/2019 07:24 PM 142 dir_test.py
05/03/2019 04:56 PM 1,766 drmscript.py
04/30/2019 06:39 AM 59 pw.bat
04/30/2019 06:18 AM 600 pw.py
4 File(s) 2,567 bytes
2 Dir(s) 6,978,912,256 bytes free
What am I doing wrong?