Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53570

Re: Unable to redirect the subprocess CMD.exe to txt file. Please help !!!

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 <wrw@mac.com>
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 <wrw@mac.com>
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" <python-list@python.org>
X-Mailer Apple Mail (2.1508)
Cc Venkatesh <venkatesh.totad@gmail.com>, William Ray Wing <wrw@mac.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6.1378221752.5461.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Sep 3, 2013, at 9:54 AM, Venkatesh <venkatesh.totad@gmail.com> wrote:

> Hello comp.lang.python Group,
> 
> I am trying to invoke a subprocess in Python as below 
> 
> import sys
> import time
> import os
> import subprocess
> DETACHED_PROCESS = 0x00000008
> 
> path = r'C:\Windows\System32\cmd.exe /k ping www.google.com -n 4 >> temp.txt'
> p = subprocess.Popen("%s"%(path), stdout = subprocess.PIPE, stderr = subprocess.STDOUT, creationflags=DETACHED_PROCESS)
> 
> With this code, unable to invoke the subprocess and hence not able to store the Ping statistics in the file.
> 
> Any help on this OR any better way of achieving this??
> 
> 
> -- 
> 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 = subprocess.Popen(['ping', '-c1', '-t1', self.target_IP], stderr=subprocess.PIPE, stdout = 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 = 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Unable to redirect the subprocess CMD.exe to txt file. Please help !!! Venkatesh <venkatesh.totad@gmail.com> - 2013-09-03 06:54 -0700
  Re: Unable to redirect the subprocess CMD.exe to txt file. Please help !!! William Ray Wing <wrw@mac.com> - 2013-09-03 10:22 -0400
  Re: Unable to redirect the subprocess CMD.exe to txt file. Please help !!! random832@fastmail.us - 2013-09-03 12:21 -0400

csiph-web