如何获得输出。 [英] how to get output.

查看:67
本文介绍了如何获得输出。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我想得到DIR / AD / B的输出。使用

python命令变量。我怎么能这样做?

谢谢,

Indu

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

推荐答案

indu_shreenath schrieb:
indu_shreenath schrieb:

嘿,

我想得到DIR / AD / B的输出。使用

python命令变量。我怎样才能做到这一点?
Hey,
I want to get the output of "DIR /AD /B" command to a varriable using
python. How can I do this?



使用子流程模块。

但是,我不确定DIR / AD / B是做什么的 - 但是有很多

在模块操作系统中运行,可以提供你想要的东西而无需调用

一个外部命令。


Diez

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


嘿,


我写了以下内容:

但它不起作用。


导入子流程为sp

尝试:

= sp.Popen(" DIR。/ AD / B",stdout = sp.PIPE)

result = p.communicate()[0]

打印结果

除外:

print" error"


这会引发错误。

DIR。 / AD / B将只列出当前目录中的目录。


谢谢,

Indu

8月9日,11日:上午46点,Diez B. Roggisch < de ... @nospam.web.dewrote:
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.web.dewrote:

indu_shreenath schrieb:
indu_shreenath schrieb:

嘿,

我想获得DIR / AD / B的输出使用

python命令变量。我怎样才能做到这一点?
Hey,
I want to get the output of "DIR /AD /B" command to a varriable using
python. How can I do this?



使用子流程模块。


但是,我不确定DIR / AD / B是做什么的 - 但是模块操作系统中有很多

函数可以提供你想要的东西而无需调用

一个外部命令。


Diez


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



我更正了下面的一个类型。


8月9日下午12:50,indu_shreen ... @ yahoo.co.in写道:
I corrected a typ below.

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

嘿,


我写了以下内容:

但它不起作用。


导入子流程为sp

尝试:

p = sp.Popen( DIR。/ AD / B,stdout = sp.PIPE)

result = p.communicate()[0]

打印结果

除外:

print" error"


这会引发错误。

DIR。 / AD / B将只列出当前目录中的目录。


谢谢,

Indu


开8月9日上午11:46,Diez B. Roggisch < de ... @nospam.web.dewrote:
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.web.dewrote:

indu_shreenath schrieb:
indu_shreenath schrieb:


嘿,

我想获得DIR / AD / B的输出使用

python命令变量。我怎样才能做到这一点?
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.


但是,我不确定DIR / AD / B是做什么的 - 但是有很多

函数模块操作系统可以提供你想要的东西,而不需要调用外部命令。
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-隐藏引用文字 -
Diez- Hide quoted text -



- 显示引用文字 -


- Show quoted text -



这篇关于如何获得输出。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆