Need help with network script

B

bbechdol

Hi everyone. I am starting to learn python and I decided to start with whatI 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. Ireally 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)
 
C

Chris Angelico

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 returnwhat 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 :)

ChrisA
 
B

bbechdol

On Thu, Jul 18, 2013 at 11:44 AM,










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 :)



ChrisA

This is as far as I have gotten. THis is all my code and it has been copiedand pasted. Thats why I am posting here. I know that the code can be better. Once I learn more it wont look like crap.
 
D

Dave Angel

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().
 
B

bbechdol

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().

I will try that. I am using Python 2.7
 
C

Chris Angelico

This is as far as I have gotten. THis is all my code and it has been copied and pasted. Thats why I am posting here. I know that the code can be better. Once I learn more it wont look like crap.

My point is that that can't be the code that always outputs "0",
because the code above would not output 0, it would terminate with
TypeError.

By the way, if you're going to use Google Groups, please read this:

http://wiki.python.org/moin/GoogleGroupsPython

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top