d*****u 发帖数: 17243 | 1 我找到一个相对简单的办法,贴一下。
自己定义一个class,
read和write代替默认的读写方式
class Pipe(subprocess.Popen):
def __init__(self, argv, timeout = 0):
self.timeout = timeout
subprocess.Popen.__init__(self, argv, stdin = subprocess.PIPE,
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
def write(self, data):
poll = select.poll()
poll.register(self.stdin.fileno(), select.POLLOUT)
fd = poll.poll(self.timeout)
if len(fd):
f = fd[0]
if f[1] > 0:
... 阅读全帖 |
|
m*****g 发帖数: 54 | 2 here is the code snippet
cmd = "xxxxxxx"
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.
STDOUT)
for line in p.stdout.readlines():
print("{0}".format(line.decode("utf-8")[0:len(line)-1])) |
|
c******n 发帖数: 4965 | 3 【 以下文字转载自 Java 讨论区 】
发信人: creation (努力自由泳50m/45sec !), 信区: Java
标 题: Re: very archaic issue :
发信站: BBS 未名空间站 (Fri Apr 29 11:58:14 2011, 美东)
one colleague replied
using ssh -t ....
would help
here is my reply to him (his approach partially works, but only when you
terminate ssh client by ctrl-C, which is SIGINT, it does not work
when the ssh is run by a daemon like hudson, and terminated with -15 )
######################################
This is a cleaner way than the hack I came up with: I foun... 阅读全帖 |
|
c******n 发帖数: 4965 | 4 【 以下文字转载自 Java 讨论区 】
发信人: creation (努力自由泳50m/45sec !), 信区: Java
标 题: Re: very archaic issue :
发信站: BBS 未名空间站 (Fri Apr 29 11:58:14 2011, 美东)
one colleague replied
using ssh -t ....
would help
here is my reply to him (his approach partially works, but only when you
terminate ssh client by ctrl-C, which is SIGINT, it does not work
when the ssh is run by a daemon like hudson, and terminated with -15 )
######################################
This is a cleaner way than the hack I came up with: I foun... 阅读全帖 |
|
c******n 发帖数: 4965 | 5 one colleague replied
using ssh -t ....
would help
here is my reply to him (his approach partially works, but only when you
terminate ssh client by ctrl-C, which is SIGINT, it does not work
when the ssh is run by a daemon like hudson, and terminated with -15 )
######################################
This is a cleaner way than the hack I came up with: I found that “normally
” the remote code terminates because it wants to print to the terminal,
Which is closed after ssh is closed, so the remote c... 阅读全帖 |
|
c******n 发帖数: 4965 | 6 one colleague replied
using ssh -t ....
would help
here is my reply to him (his approach partially works, but only when you
terminate ssh client by ctrl-C, which is SIGINT, it does not work
when the ssh is run by a daemon like hudson, and terminated with -15 )
######################################
This is a cleaner way than the hack I came up with: I found that “normally
” the remote code terminates because it wants to print to the terminal,
Which is closed after ssh is closed, so the remote c... 阅读全帖 |
|
d*****u 发帖数: 17243 | 7 程序需要往subprocess里不断输入数据,然后读出数据
python自带的那个communicate()必须等subprocess完成才返回数据,显然很多时候都
不好用
直接用stdin stdout经常会碰到deadlock |
|
X***n 发帖数: 366 | 8 import subprocess
subprocess.call(["ls", "-l", "/etc/resolv.conf"]) |
|
d******e 发帖数: 2265 | 9 subprocess, redirect is kind of tricky and hard.
search subprocess redict will give you lots of hints.
I personally like the
with blah as blah:
call(blahlist, outputfile= blah)
way |
|
b*********n 发帖数: 1258 | 10 我是hadoop 菜鸟,第一次用
我的job 就是个很简单的map job, no reducer,
mapper 也就是一些很简单的命令,会有一些输出到stderr, stdout
我的hadoop 命令output option:
"-outputformat org.apache.hadoop.mapred.lib.NullOutputFormat " .
"-output NONE " .
map 一直fail,error message 如下,不论我是否supress所有的stderr, stdout,一直
是下面相同的error message.
那位高手可不可以指点一二。谢谢
java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess
failed with code 143
at org.apache.hadoop.streaming.PipeMapRed.waitOutputThreads(PipeMapRed.
java:311)
at org.apac |
|
r****y 发帖数: 26819 | 11 不错,虽然post install的script出了点小错,但还是装上了,能用。
Setting up org.xbmc.xbmc-atv2 (10.0-0) ...
No matching processes were found
dpkg: error processing org.xbmc.xbmc-atv2 (--configure):
subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
org.xbmc.xbmc-atv2
E: Sub-process /usr/bin/dpkg returned an error code (1) |
|
P****e 发帖数: 385 | 12 回到ios4.2.1(apple tv 4.1.1),结果看天翼还是看到5-10分钟左右就
崩溃,后来发现是xbmc自己每隔5-10分钟就崩溃。具体安装过程如下:
之前上到ios 4.3有问题,于是去http://www.felixbruns.de/iPod/firmware/ 下载了一个4.2.1的firmware,然后用pwnage做了一个AppleTV2,1_4.2.1_8C154_Custom_Restore。从itunes 10.1.1 restore,一切顺利。
用apt-get装xbmc,安装的时候蹦出几行错:
Setting up org.xbmc.xbmc-atv2 (10.0-7) ...
No matching processes were found
dpkg: error processing org.xbmc.xbmc-atv2 (--configure):
subprocess post-installation script returned error exit status 1
Errors were encountered while proces... 阅读全帖 |
|
s*****e 发帖数: 33 | 13 Check the API of java.lang.Process, it will give you the output. Then you can
do whatever you want.
line
line
result
subprocess |
|
a*****i 发帖数: 4391 | 14
Are you trying to use VNC to accomplish emacs server? That is a serious
overkill.
server-start is an interactive compiled Lisp function in `server.el'.
(server-start &optional LEAVE-DEAD)
Allow this Emacs process to be a server for client processes.
This starts a server communications subprocess through which
client "editors" can send your editing commands to this Emacs
job. To use the server, set up the program `emacsclient' in the
Emacs distribution as your standard "editor". |
|
F*******i 发帖数: 190 | 15 Setting up ia32-libwmf0.2-7 (0.2.8.4-6.1~22) ...
W: libwmf0.2-7: Application not found.
dpkg: error processing ia32-libwmf0.2-7 (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
ia32-libwmf0.2-7
E: Sub-process /usr/bin/dpkg returned an error code (1)
请问有什么办法可以去掉这个error 吗?
Thanks! |
|
j*****h 发帖数: 2577 | 16 /var/cache/apt/archives/libc6_2.11.1-0ubuntu7.2_amd64.deb: subprocess new
post-removal script killed by signal (Segmentation fault) |
|
m**k 发帖数: 290 | 17 能用python就别用perl了。
python 里有 subprocess.Popen
per里可以 open FD "| c-prog" |
|
s****h 发帖数: 921 | 18 我发现IDLE常常会死掉。
而且有时候打不开,点击后直接提示出错:
IDLE subprocess error.
Socket Error: connection refused.
有没有其他的比较稳定的集成环境的Python?
我在Winxp下运行。 |
|
l********a 发帖数: 1154 | 19 直接上次的当函数就行了,
#! /usr/bin/env python
def getAcronym(s):
return ''.join([x for x in s.title() if x.isupper()])
# main entry
fnin = raw_input('Please specify the input filename:\n')
fnout = raw_input('Please specify the output filename:\n')
sout = ''
if len(fnin.strip())>0 and len(fnout.strip())>0:
fin = open(fnin,'r')
for sline in fin.readlines():
sout += getAcronym(sline)+'\n'
fin.close()
fout = open(fnout,'w')
fout.write(sout)
fout.close()
print 'Done'
els... 阅读全帖 |
|
y****e 发帖数: 23939 | 20 我的Python程序,用multi-thread作计算。在Linux和MacOS X下都运行很好。但是到了
Windows 7下,运算中间总是Python interpreter crash。我是用subprocess.Popen
launch那个运算函数的。哪位Python高手能指点一下呢,非常感谢。 |
|
d****p 发帖数: 685 | 21 Use subprocess.Popen to launch a function? How?
Or you meant launching a process that does the computation? |
|
l*********s 发帖数: 5409 | 22 To package functionalities into modules, you can employ either approach, but
what are the pros and cons? (if creation subprocess/threads is only done
during initialization)
And on servers,does it matter that a process requires more resource than
thread, if I am mostly concerned about performance only? |
|
|
|
D***n 发帖数: 6804 | 25 Python是task driven的,完全不用学那么多,上手就用。
最多把几个常用的东西弄明白,能想到的比如:
1)比如什么list, dict,以及如何在list/dict的基础上添加定制的方法和属性。
2)那些__xxxx__的内部函数和属性,
3)模块是怎么回事
4)常见的系统库,比如os,sys, subprocess, request,logging, elementtree等等。
5)PDB
6)根据需要可以考虑学django, numpy之类的。
基本上明白这些干活时加上 python doc, stackoverflow, google就可以干活了。 |
|
D***n 发帖数: 6804 | 26 subprocess.call(["wc", "-w"]) |
|
e*********6 发帖数: 3453 | 27 是直接在bash里边写个循环,还是先用python或者perl写个循环创造一个非常长的bash
文件?
感觉在bash里写循环比较高端,省资源。用python创造一个长bash虽然感觉有些弱智,
但是也同时用subprocess去执行然后删掉这个bash的话,也是一步能完成。 |
|
n******7 发帖数: 12463 | 28 另外我感觉python调用系统命令比较麻烦,又有几种方式,os.system, subprocess之
类的
比perl差不少 |
|
|
c*****m 发帖数: 1160 | 30 from subprocess import Popen, PIPE, STDOUT
p = Popen(['myapp'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
stdout_data = p.communicate(input='data_to_write')[0]
往 stdin里写 |
|
j*****n 发帖数: 1545 | 31 python 在 big data 这个领域就是 jython or subprocess python, 和 jvm
language 不可同日而语,慢的太多了。 |
|
j*****n 发帖数: 1545 | 32 python 在 big data 这个领域就是 jython or subprocess python, 和 jvm
language 不可同日而语,慢的太多了。 |
|
d********g 发帖数: 10550 | 33 因为楼主没有写全,这两个脚本一个是启动asterisk一个是启动gui的,楼主漏了gui的
脚本,也漏了另外一个执行/opt/etc/init.d下文件的脚本。gui脚本漏了无所谓,
S51astadmin也可以不要,不过执行init.d下文件的脚本漏了是肯定没办法把asterisk
启动起来的。具体参考原始地址:
http://www.fivn.com/products/asterisk.html
要简单就直接在router里用/opt/sbin/asterisk -q,知道怎么写bash脚本可以把
S50asterisk那个拿来参考,里面也是用asterisk -q启动的,只是多了自动备份和恢复
一些数据的功能,可要可不要
最简单的启动脚本写在router里即可(假设optware装在/jffs/opt,同时挂在/opt):
if [ ! -d /opt/etc ]; then
mount -o bind /jffs/opt /opt
/opt/sbin/asterisk -q
fi
这个主要是检查一下/opt是否已经mount了,不然router不稳定的情况会触发好多次
... 阅读全帖 |
|
d********g 发帖数: 10550 | 34 因为楼主没有写全,这两个脚本一个是启动asterisk一个是启动gui的,楼主漏了gui的
脚本,也漏了另外一个执行/opt/etc/init.d下文件的脚本。gui脚本漏了无所谓,
S51astadmin也可以不要,不过执行init.d下文件的脚本漏了是肯定没办法把asterisk
启动起来的。具体参考原始地址:
http://www.fivn.com/products/asterisk.html
要简单就直接在router里用/opt/sbin/asterisk -q,知道怎么写bash脚本可以把
S50asterisk那个拿来参考,里面也是用asterisk -q启动的,只是多了自动备份和恢复
一些数据的功能,可要可不要
最简单的启动脚本写在router里即可(假设optware装在/jffs/opt,同时挂在/opt):
if [ ! -d /opt/etc ]; then
mount -o bind /jffs/opt /opt
/opt/sbin/asterisk -q
fi
这个主要是检查一下/opt是否已经mount了,不然router不稳定的情况会触发好多次
... 阅读全帖 |
|