[Tutor] CGI-version not working while similar command-line script is fine

Gerhard Venter s.venter at ntlworld.com
Mon Sep 6 10:19:51 CEST 2004


Hi Kent

No, although I did not have the "http://" in my email, I did enter it in
my web form.  So it isn't that.   (And my version of Lynx doesn't
require it)

But the interesting thing is that the line below which you suggested
works in a Python command prompt, but not in Idle or Pythonwin.
Perhaps CGI has the same limitation as these tools.
print os.popen(r'c:\bin\lynx.exe -dump http://www.google.com').read()

Likewise (I've resorted to using a temp file, but even that isn't
working), the line below works in a Python command prompt but not in CGI.
os.system(r'start /B c:\bin\lynx.exe -dump http://www.google.com >
"F:\logs\temp.txt"')

Gerhard



Kent Johnson wrote:

> I just tried this with Lynx Version 2.8.4rel.1-mirabilos:
> > lynx --dump www.google.com
>
> I didn't get any output. If I try
> > lynx --dump http://www.google.com
> then it works. Could it be that simple?
>
> Also this works for me:
> >>> import os
> >>> print os.popen(r'C:\Downloads\Apps\LYNX\LYNX.EXE -dump 
> http://www.google.com').read()
>
> Kent
>
> At 05:08 PM 9/5/2004 +0100, Gerhard Venter wrote:
>
>> Hi Kent
>>
>> Thanks - my code is below.  It should output a plain text version of 
>> any website
>>
>> G
>>
>> Kent Johnson wrote:
>>
>>> This should work. My guess is you have an error in your script, 
>>> maybe a problem with quoting or string substitution. Can you show us 
>>> the script that is having trouble?
>>
>> import cgi, os
>> import cgitb; cgitb.enable()
>>
>> form = cgi.FieldStorage()
>> website = form["websitename"].value
>> command = 'lynx --dump ' + website
>> k=os.popen(command, 'r')
>>
>> print 'Content-type: text/plain'
>> print
>>
>> #print command  (this shows the right thing- for example lynx --dump 
>> www.google.com)
>> for line in k.readlines():
>>      print(line)
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
>



More information about the Tutor mailing list