Path: csiph.com!usenet.pasdenom.info!aioe.org!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'sys': 0.07; 'subject:help': 0.08; 'string': 0.09; 'exit': 0.09; 'ping': 0.09; 'python': 0.11; 'command.': 0.16; 'elsewhere.': 0.16; 'received:mac.com': 0.16; 'stderr': 0.16; 'stdout': 0.16; 'subject:txt': 0.16; 'venkatesh': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'received:10.0.1': 0.19; 'code,': 0.22; 'import': 0.22; 'cc:addr:gmail.com': 0.22; 'to:name:python-list@python.org': 0.22; 'cc:2**1': 0.23; 'parse': 0.24; 'file.': 0.24; 'switch': 0.26; 'defined': 0.27; 'am,': 0.29; 'returned': 0.30; 'url:mailman': 0.30; 'extract': 0.31; 'invoke': 0.31; 'sep': 0.31; 'skip:c 30': 0.32; 'url:python': 0.33; 'subject:the': 0.34; 'skip:s 30': 0.35; 'achieving': 0.36; 'url:listinfo': 0.36; 'charset:us-ascii': 0.36; 'received:10.0': 0.36; 'similar': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:10': 0.37; 'received:17': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'unable': 0.39; 'url:mail': 0.40; 'complete': 0.62; 'group,': 0.63; 'subject:. ': 0.67; 'containing': 0.69; 'address,': 0.75; 'header:In-reply- to:1': 0.84; '2013,': 0.91 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.10.8794,1.0.431,0.0.0000 definitions=2013-09-03_06:2013-09-03,2013-09-03,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1305240000 definitions=main-1309030039 Content-Type: text/plain; charset=us-ascii MIME-version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: Unable to redirect the subprocess CMD.exe to txt file. Please help !!! From: William Ray Wing In-reply-to: <3c50a8aa-261f-447d-b07c-cdad3a5465e0@googlegroups.com> Date: Tue, 03 Sep 2013 10:22:22 -0400 Content-transfer-encoding: quoted-printable References: <3c50a8aa-261f-447d-b07c-cdad3a5465e0@googlegroups.com> To: "python-list@python.org" X-Mailer: Apple Mail (2.1508) Cc: Venkatesh , William Ray Wing X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378221752 news.xs4all.nl 15902 [2001:888:2000:d::a6]:48788 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53570 On Sep 3, 2013, at 9:54 AM, Venkatesh wrote: > Hello comp.lang.python Group, >=20 > I am trying to invoke a subprocess in Python as below=20 >=20 > import sys > import time > import os > import subprocess > DETACHED_PROCESS =3D 0x00000008 >=20 > path =3D r'C:\Windows\System32\cmd.exe /k ping www.google.com -n 4 >> = temp.txt' > p =3D subprocess.Popen("%s"%(path), stdout =3D subprocess.PIPE, stderr = =3D subprocess.STDOUT, creationflags=3DDETACHED_PROCESS) >=20 > With this code, unable to invoke the subprocess and hence not able to = store the Ping statistics in the file. >=20 > Any help on this OR any better way of achieving this?? >=20 >=20 > --=20 > https://mail.python.org/mailman/listinfo/python-list I use the following in OS-X, should be very similar in Windows. import subprocess ping_result =3D subprocess.Popen(['ping', '-c1', '-t1', = self.target_IP], stderr=3Dsubprocess.PIPE, stdout =3D = subprocess.PIPE).communicate()[0] self.target_IP is a string containing the IP address, which is defined = elsewhere. ping_result contains the complete returned string from the ping command. = Note the -c switch (count =3D 1 ping packet) and the -t switch (force = exit after one second). you will have to parse the returned string to extract the stats. -Bill=