Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1828702
  • 博文数量: 283
  • 博客积分: 10141
  • 博客等级: 上将
  • 技术积分: 2931
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-21 14:33
文章分类

全部博文(283)

文章存档

2013年(2)

2012年(2)

2011年(17)

2010年(36)

2009年(17)

2008年(18)

2007年(66)

2006年(105)

2005年(20)

分类:

2007-03-27 09:25:56

(1) Python //前面的文章中已经提到过了
http://blog.chinaunix.net/u/12325/showart_217175.html

两种方法,一种是且Popen.
output = subprocess.Popen(['ls','-l'],stdout=subprocess.PIPE,shell=True).commun
icate()
print output[0]
 
另外一种则可返回状态与调用的shell命令的输出结果
>>> import commands
>>> status, output = commands.getstatusoutput('ls -l')


(2) Perl //这个相比之下就简单多了
$out=`shell command`

(3) Shell
最简单的方法是这样:
    out=`shell command`
或者
    out=$(shell command)
不过要注意的是,如果shell command的输出结果为多行,而这样放进变量中的时候,默认的echo $out是不输出换行的(参看IFS相关的文档),echo "$out"就可以了。

(4) C
     #include
     int system(const char *string);

当调用system("command");的时候,执行结果是打在标准输出的。

阅读(8371) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~