473,804 Members | 5,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get output.

Hey,
I want to get the output of "DIR /AD /B" command to a varriable using
python. How can I do this?
Thanks,
Indu

Aug 9 '07 #1
14 2055
indu_shreenath schrieb:
Hey,
I want to get the output of "DIR /AD /B" command to a varriable using
python. How can I do this?
Using the subprocess-module.
However, I'm not sure what DIR /AD /B does - but there are many
functions in module os that might deliver what you want without invoking
an external command.

Diez
Aug 9 '07 #2
Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
= sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.

Thanks,
Indu
On Aug 9, 11:46 am, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
indu_shreenath schrieb:
Hey,
I want to get the output of "DIR /AD /B" command to a varriable using
python. How can I do this?

Using the subprocess-module.

However, I'm not sure what DIR /AD /B does - but there are many
functions in module os that might deliver what you want without invoking
an external command.

Diez

Aug 9 '07 #3
I corrected a typ below.

On Aug 9, 12:50 pm, indu_shreen...@ yahoo.co.in wrote:
Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.

Thanks,
Indu

On Aug 9, 11:46 am, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
indu_shreenath schrieb:
Hey,
I want to get the output of "DIR /AD /B" command to a varriable using
python. How can I do this?
Using the subprocess-module.
However, I'm not sure what DIR /AD /B does - but there are many
functions in module os that might deliver what you want without invoking
an external command.
Diez- Hide quoted text -

- Show quoted text -

Aug 9 '07 #4
I corrected a typ below.

On Aug 9, 12:50 pm, indu_shreen...@ yahoo.co.in wrote:
Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.

Thanks,
Indu

On Aug 9, 11:46 am, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
indu_shreenath schrieb:
Hey,
I want to get the output of "DIR /AD /B" command to a varriable using
python. How can I do this?
Using the subprocess-module.
However, I'm not sure what DIR /AD /B does - but there are many
functions in module os that might deliver what you want without invoking
an external command.
Diez- Hide quoted text -

- Show quoted text -

Aug 9 '07 #5
in************@ yahoo.co.in wrote:
I corrected a typ below.

On Aug 9, 12:50 pm, indu_shreen...@ yahoo.co.in wrote:
>Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.
try:
...
except:
print "error"

is a really bad idea because it hides any meaningful and therefore valuable
information about the error.

IIRC the "dir" command is internal to the dos shell and therefore has to be
called indirectly. The actual command is "cmd", not "dir":

[following snippet found at
http://www.python-forum.de/viewtopic...f75c32cf67856]
>>import subprocess
args = ["cmd", "/C", "dir", "J:\\", "/O", "/AD", "/B"]
process = subprocess.Pope n(args, stdout = subprocess.PIPE , stderr =
subprocess.STDO UT)
>>print process.stdout. read()
If you just want a list of subdirectories, here's a better approach:
>>def directories(fol der):
.... return os.walk(folder) .next()[1]
>>directories(" .")
[snip list of subdirectories of cwd]

Peter
Aug 9 '07 #6
in************@ yahoo.co.in wrote:
I corrected a typ below.

On Aug 9, 12:50 pm, indu_shreen...@ yahoo.co.in wrote:
>Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.
try:
...
except:
print "error"

is a really bad idea because it hides any meaningful and therefore valuable
information about the error.

IIRC the "dir" command is internal to the dos shell and therefore has to be
called indirectly. The actual command is "cmd", not "dir":

[following snippet found at
http://www.python-forum.de/viewtopic...f75c32cf67856]
>>import subprocess
args = ["cmd", "/C", "dir", "J:\\", "/O", "/AD", "/B"]
process = subprocess.Pope n(args, stdout = subprocess.PIPE , stderr =
subprocess.STDO UT)
>>print process.stdout. read()
If you just want a list of subdirectories, here's a better approach:
>>def directories(fol der):
.... return os.walk(folder) .next()[1]
>>directories(" .")
[snip list of subdirectories of cwd]

Peter
Aug 9 '07 #7
in************@ yahoo.co.in wrote:
I corrected a typ below.

On Aug 9, 12:50 pm, indu_shreen...@ yahoo.co.in wrote:
>Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.
try:
...
except:
print "error"

is a really bad idea because it hides any meaningful and therefore valuable
information about the error.

IIRC the "dir" command is internal to the dos shell and therefore has to be
called indirectly. The actual command is "cmd", not "dir":

[following snippet found at
http://www.python-forum.de/viewtopic...f75c32cf67856]
>>import subprocess
args = ["cmd", "/C", "dir", "J:\\", "/O", "/AD", "/B"]
process = subprocess.Pope n(args, stdout = subprocess.PIPE , stderr =
subprocess.STDO UT)
>>print process.stdout. read()
If you just want a list of subdirectories, here's a better approach:
>>def directories(fol der):
.... return os.walk(folder) .next()[1]
>>directories(" .")
[snip list of subdirectories of cwd]

Peter
Aug 9 '07 #8
in************@ yahoo.co.in wrote:
I corrected a typ below.

On Aug 9, 12:50 pm, indu_shreen...@ yahoo.co.in wrote:
>Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.
try:
...
except:
print "error"

is a really bad idea because it hides any meaningful and therefore valuable
information about the error.

IIRC the "dir" command is internal to the dos shell and therefore has to be
called indirectly. The actual command is "cmd", not "dir":

[following snippet found at
http://www.python-forum.de/viewtopic...f75c32cf67856]
>>import subprocess
args = ["cmd", "/C", "dir", "J:\\", "/O", "/AD", "/B"]
process = subprocess.Pope n(args, stdout = subprocess.PIPE , stderr =
subprocess.STDO UT)
>>print process.stdout. read()
If you just want a list of subdirectories, here's a better approach:
>>def directories(fol der):
.... return os.walk(folder) .next()[1]
>>directories(" .")
[snip list of subdirectories of cwd]

Peter
Aug 9 '07 #9
in************@ yahoo.co.in wrote:
I corrected a typ below.

On Aug 9, 12:50 pm, indu_shreen...@ yahoo.co.in wrote:
>Hey,

I did write the following:
but it does not work.

import subprocess as sp
try:
p = sp.Popen("DIR . /AD /B", stdout=sp.PIPE)
result = p.communicate()[0]
print result
except:
print "error"

This throws error.
DIR . /AD /B will list out only directories in the current directory.
try:
...
except:
print "error"

is a really bad idea because it hides any meaningful and therefore valuable
information about the error.

IIRC the "dir" command is internal to the dos shell and therefore has to be
called indirectly. The actual command is "cmd", not "dir":

[following snippet found at
http://www.python-forum.de/viewtopic...f75c32cf67856]
>>import subprocess
args = ["cmd", "/C", "dir", "J:\\", "/O", "/AD", "/B"]
process = subprocess.Pope n(args, stdout = subprocess.PIPE , stderr =
subprocess.STDO UT)
>>print process.stdout. read()
If you just want a list of subdirectories, here's a better approach:
>>def directories(fol der):
.... return os.walk(folder) .next()[1]
>>directories(" .")
[snip list of subdirectories of cwd]

Peter
Aug 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8139
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br>\n"; print STDERR "PERL This is text sent to STDERR<br>\n"; $output="PERL Some output:<br>\n"; for ($i=0; $i<5; $i++) {
4
15080
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that this program returns. I'm just missing the stepshere. I know that I can set the Shell command to an integer,but this only returns a 0 to me telling me that it executed, notwhat is being returned to the console by that application. Isthere a way to...
0
2066
by: newbie | last post by:
i'm a newbie of c language. can anyone help me to implement the code so that I can get the ciphertext from the output. thanks. #ifndef _3DES_H #define _3DES_H #ifndef uint8 #define uint8 unsigned char #endif
3
4667
by: undshan | last post by:
I am writing a code that needs to open a file, create an output file, run through my function, prints the results to the output file, and closes them within a loop. Here is my code: #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #include "util.h" //Main Loop
2
3383
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables @idUser int OUTPUT,
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.