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


Groups > comp.lang.python > #50820

Re: Need help with network script

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'string.': 0.05; 'sys': 0.07; 'subject:help': 0.08; 'integral': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'python': 0.11; 'macs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'thu,': 0.19; 'version.': 0.19; 'code,': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; '(a)': 0.24; 'specify': 0.24; 'tells': 0.24; 'looks': 0.24; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'gives': 0.31; 'code': 0.31; 'crash': 0.31; 'selection': 0.32; 'run': 0.32; 'guess': 0.33; 'actual': 0.34; 'subject:with': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; '2.6': 0.36; 'everyone.': 0.36; 'doing': 0.36; 'wrong': 0.37; 'starting': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'hope': 0.61; 'simple': 0.61; "you're": 0.61; 'back': 0.62; 'decided': 0.64; 'subject:Need': 0.64; 'here': 0.66; 'between': 0.67; 'home': 0.69; 'jul': 0.74; '11:44': 0.84; '2.7.': 0.84; 're-type': 0.84; 'differences': 0.93; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Need help with network script
Date Wed, 17 Jul 2013 22:06:27 -0400
References <c3e795f9-b195-4a51-99ff-9289f0277280@googlegroups.com> <CAPTjJmovkdDPOvnSuBiukvjsSzH6tsW-DPmQ3OAj_0WmePrjDA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 174.32.174.30
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7
In-Reply-To <CAPTjJmovkdDPOvnSuBiukvjsSzH6tsW-DPmQ3OAj_0WmePrjDA@mail.gmail.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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4821.1374113204.3114.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374113204 news.xs4all.nl 15916 [2001:888:2000:d::a6]:45116
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50820

Show key headers only | View raw


On 07/17/2013 09:50 PM, Chris Angelico wrote:
> On Thu, Jul 18, 2013 at 11:44 AM,  <bbechdol@gmail.com> wrote:
>> Hi everyone. I am starting to learn python and I decided to start with what I though was a simple script but I guess now. All I want to do is return what current network location I am using on my mac. Every time I run it, it gives me back a 0. I don't know what I am doing wrong so here is my code. I really hope some one can help me. This script is unique to MACS btw.
>>
>> import sys
>> import subprocess
>>
>> loc = "scselect"
>> srn = "scselect SRN"
>> home = "scselect HOME"
>>
>> a = subprocess.call(loc, shell=True, stdout=subprocess.PIPE)
>> b = subprocess.call(srn, shell=True, stdout=subprocess.PIPE)
>> c = subprocess.call(home, shell=True, stdout=subprocess.PIPE)
>>
>> print "\n##### NETWORK SELECTION #####"
>> print "\nYour current location is set to \n%s" (a)
>
> Your last line here looks wrong. Is this really the code you're using?
> This code will crash with a TypeError, because you're trying to call a
> string.
>
> Copy and paste your actual code, don't re-type it :)
>
In addition to reposting using copy/paste, please specify the Python 
version.  There were differences between 2.6 and 2.7.

Short answer is that subprocess.call() returns an integral returncode. 
So zero tells you that shelling to the subprocess succeeded.

Perhaps you'd like to use  subprocess.check_output() instead of 
subprocess.call().


-- 
DaveA

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


Thread

Need help with network script bbechdol@gmail.com - 2013-07-17 18:44 -0700
  Re: Need help with network script Chris Angelico <rosuav@gmail.com> - 2013-07-18 11:50 +1000
    Re: Need help with network script bbechdol@gmail.com - 2013-07-17 18:59 -0700
      Re: Need help with network script bbechdol@gmail.com - 2013-07-17 19:01 -0700
      Re: Need help with network script Chris Angelico <rosuav@gmail.com> - 2013-07-18 15:38 +1000
  Re: Need help with network script Dave Angel <davea@davea.name> - 2013-07-17 22:06 -0400
    Re: Need help with network script bbechdol@gmail.com - 2013-07-17 19:19 -0700

csiph-web