python - Subprocess check_output(['dir']) not as expected -


i want see contents of windows' dir command in shell. have cygwin , mingw installed. code,

import subprocess sub print sub.check_output(['dir']) 

it gets parsed as

dccircuits.py idle\ (idle.pyw).lnk newpy.bat change\ fileops.readfile\ to\ match\ line\ indent.txt chext clark\ wifi downloading\ again drumset\ project idle.bat\ -\ shortcut.lnk idle.pyw\ -\ shortcut.lnk indexprogramfiles.py maps\ traveler ordereddict.txt pipfreeze.txt remote\ wireless searchcontents.py sleep\ calculator\ project tracertips.py 

i trying display output this.

 volume in drive c ti10693600d  volume serial number 240d-7f0a   directory of c:\users\clayton  02/03/2016  10:22    <dir>          . 02/03/2016  10:22    <dir>          .. 11/05/2015  03:07 pm    <dir>          .android 11/03/2015  03:10 pm    <dir>          .eclipse 08/14/2015  12:02 pm    <dir>          .idlerc 11/01/2015  10:38 pm    <dir>          .jmc 01/04/2016  09:33    <dir>          .matplotlib 01/08/2016  10:18    <dir>          .oracle_jre_usage 03/29/2015  05:49 pm    <dir>          .pdfsam 01/26/2016  09:47 pm    <dir>          .phet 09/04/2015  02:43 pm    <dir>          3d objects 01/29/2016  12:06 pm    <dir>          contacts 02/05/2016  10:35    <dir>          desktop 02/04/2016  08:38 pm    <dir>          documents 02/04/2016  04:31 pm    <dir>          downloads 01/29/2016  12:06 pm    <dir>          favorites 02/04/2016  05:25 pm    <dir>          google drive 01/29/2016  12:06 pm    <dir>          links 01/29/2016  12:06 pm    <dir>          music 12/24/2015  03:10 pm    <dir>          onedrive 02/03/2016  03:36 pm    <dir>          pictures 01/29/2016  12:06 pm    <dir>          saved games 01/29/2016  12:06 pm    <dir>          searches 11/28/2014  10:14 pm    <dir>          shared 04/12/2015  03:23 pm    <dir>          tracing 01/29/2016  12:06 pm    <dir>          videos                0 file(s)              0 bytes               26 dir(s)  480,478,224,384 bytes free 

when take out cygwin , mingw out of path, error happens:

traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "c:\python27\lib\subprocess.py", line 566, in check_output     process = popen(stdout=pipe, *popenargs, **kwargs)   file "c:\python27\lib\subprocess.py", line 710, in __init__     errread, errwrite)   file "c:\python27\lib\subprocess.py", line 958, in _execute_child     startupinfo) windowserror: [error 2] system cannot find file specified 

is there way desired outcome without having store data in external file?

thanks in advance.

passing shell=true check_output seems work. suspect dir implemented shell (cmd) builtin rather independent executable.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -