[Tutor] (no subject)

Glen Bunting Glen@ihello-inc.com
Thu, 8 Mar 2001 15:29:16 -0800


Forgot to say what the problem was.  When I try to run it, I get an error
that curl couldn't resolve host SERVER.  It seems to me that instead of
using the url that is in the variable, it tries to use the variable itself.
SERVER is contains two lines.  One line is a url the second line is what I
need to find on the page.  What I'm trying to do is rewrite a sh script in
python.  Please let me know if I should post the original script and what
I've done so far.

Glen Bunting 




-----Original Message-----
From: Glen Bunting [mailto:Glen@ihello-inc.com]
Sent: Thursday, March 08, 2001 2:16 PM
To: 'Daniel Yoo'
Cc: tutor@python.org
Subject: RE: [Tutor] (no subject)


Thanks Danny,

I have another question in the same area.  

Here is the code that I have so far:
>>>SERVER = popen('cut --character=5- eachName')
>>>LOOK_FOR = popen('cut --character=9- eachName')
RESULTS = os.system(curl --include --max-time 30 SERVER | grep LOOK_FOR')

I just need to verify that what is specified in LOOK_FOR is there or not.
What is wrong with the last line?

Glen Bunting 




-----Original Message-----
From: Daniel Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: Thursday, March 08, 2001 12:48 PM
To: Glen Bunting
Cc: tutor@python.org
Subject: Re: [Tutor] (no subject)


On Thu, 8 Mar 2001, Glen Bunting wrote:

> I have what I hope is a very easy question.  I need to save the
> results of a command to a variable but I am not sure how to go about
> doing it.  This is what I have done so far:
> 
> >>>import os
> >>>test  = os.system('cut --character=5- ActsAutomation,ihello,com')

The os.system() function returns the "errorlevel" of its command, which is
often different from its printed output.  (This errorlevel value is useful
when you're writing shell scripts that check for the success or failure of
a command.) That's where the zero is coming from.

What you'll want to use instead is os.popen(), which gives us a
"file"-like object.  From this, we can read off the program's output.

For example:

###
>>> import os
>>> output = os.popen('ls *.txt').read()
>>> print output
indrel.txt
list.txt
rules.txt
sentenceword.txt
###

will call the ls command, get the file, read() off all of its string
contents, and store that into our output.

If you have more questions, please feel free to ask us.


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor