Hi all, I have a problem using wget and Popen. I hope someone can help.
-- Problem --
I want to use the command:
wget -nv -O "dir/cpan.txt" "http://search.cpan.org "
and capture all it's stdout+stderr.
(Note that option -O requires 'dir' to be existing before wget is executed)
Popen doesn't work, while os.system and shell do. Popen will give the error:
dir/cpan.txt: No such file or directory
While os.system and shell will give the correct result:
06:52:40 URL: http://search.cpan.org/ [3657/3657] -"dir1/cpan.txt" [1]
-- Background info about wget --
-Option -nv: -nv, --no-verbose turn off verboseness, without
being quiet.
-Option -O: -O, --output-document=FILE write documents to FILE.
Note that wget requires any directories in the file-path of option -O to be
existing before the wget command is executed.
-- Python Code using Popen with cmd arg list --
# imports
import os
from subprocess import Popen, PIPE
# vars and create dir
cmd_set = ['wget', '-nv', '-O dir/cpan.txt', 'http://search.span.org ']
cmd = ' '.join(cmd_set)
print "cmd: " + cmd
try:
os.makedirs('di r')
except:
print 'dir already exists'
# execute using Popen (does NOT work)
proc = Popen(cmd_set, stdout=PIPE, stderr=PIPE)
return_code = proc.wait()
if return_code == 0:
print "Success:\n %s" % (proc.stdout.re ad() + proc.stderr.rea d())
else:
print "Failure %s:\n%s" % (return_code, proc.stderr.rea d() +
proc.stdout.rea d())
# execute using os.system (does work)
os.system(cmd)
-- Python code output of Popen --
Failure 1:
dir/cpan.txt: No such file or directory
-- Question --
Why is Popen unable to correctly execute the wget, while os.system can? 3 7850
"Jesse" <ha**@spam.comw rites:
Hi all, I have a problem using wget and Popen. I hope someone can help.
-- Problem --
I want to use the command:
wget -nv -O "dir/cpan.txt" "http://search.cpan.org "
and capture all it's stdout+stderr.
(Note that option -O requires 'dir' to be existing before wget is executed)
Popen doesn't work, while os.system and shell do. Popen will give the error:
dir/cpan.txt: No such file or directory
While os.system and shell will give the correct result:
06:52:40 URL:http://search.cpan.org/ [3657/3657] -"dir1/cpan.txt" [1]
[...]
-- Python Code using Popen with cmd arg list --
# imports
import os
from subprocess import Popen, PIPE
# vars and create dir
cmd_set = ['wget', '-nv', '-O dir/cpan.txt', 'http://search.span.org ']
cmd = ' '.join(cmd_set)
print "cmd: " + cmd
try:
os.makedirs('di r')
except:
print 'dir already exists'
# execute using Popen (does NOT work)
proc = Popen(cmd_set, stdout=PIPE, stderr=PIPE)
return_code = proc.wait()
if return_code == 0:
print "Success:\n %s" % (proc.stdout.re ad() + proc.stderr.rea d())
else:
print "Failure %s:\n%s" % (return_code, proc.stderr.rea d() +
proc.stdout.rea d())
# execute using os.system (does work)
os.system(cmd)
-- Python code output of Popen --
Failure 1:
dir/cpan.txt: No such file or directory
-- Question --
Why is Popen unable to correctly execute the wget, while os.system can?
I don't know exactly why in this case Popen doesn't work,
but the counterpart of os.system is Popen with option shell=True
and the first parameter should be a string instead of list.
That seems to work:
proc = Popen("wget -nv -O dir/cpan.txt http://search.span.org ",
shell=True, stdout=PIPE, stderr=PIPE)
and this variant seems to work too:
cmd_set = ['wget', '-nv', '-O', 'dir/cpan.txt', 'http://search.span.org ']
--
HTH,
Rob
Thx Rob!
Your solution works perfect!
"Rob Wolfe" <rw@smsnet.plwr ote in message
news:87******** ****@merkury.sm snet.pl...
"Jesse" <ha**@spam.comw rites:
>Hi all, I have a problem using wget and Popen. I hope someone can help.
-- Problem -- I want to use the command: wget -nv -O "dir/cpan.txt" "http://search.cpan.org " and capture all it's stdout+stderr. (Note that option -O requires 'dir' to be existing before wget is executed)
Popen doesn't work, while os.system and shell do. Popen will give the error: dir/cpan.txt: No such file or directory
While os.system and shell will give the correct result: 06:52:40 URL:http://search.cpan.org/ [3657/3657] -"dir1/cpan.txt" [1]
[...]
>-- Python Code using Popen with cmd arg list -- # imports import os from subprocess import Popen, PIPE
# vars and create dir cmd_set = ['wget', '-nv', '-O dir/cpan.txt', 'http://search.span.org '] cmd = ' '.join(cmd_set) print "cmd: " + cmd try: os.makedirs('d ir') except: print 'dir already exists'
# execute using Popen (does NOT work) proc = Popen(cmd_set, stdout=PIPE, stderr=PIPE) return_code = proc.wait() if return_code == 0: print "Success:\n %s" % (proc.stdout.re ad() + proc.stderr.rea d()) else: print "Failure %s:\n%s" % (return_code, proc.stderr.rea d() + proc.stdout.re ad())
# execute using os.system (does work) os.system(cm d)
-- Python code output of Popen -- Failure 1: dir/cpan.txt: No such file or directory
-- Question -- Why is Popen unable to correctly execute the wget, while os.system can?
I don't know exactly why in this case Popen doesn't work,
but the counterpart of os.system is Popen with option shell=True
and the first parameter should be a string instead of list.
That seems to work:
proc = Popen("wget -nv -O dir/cpan.txt http://search.span.org ",
shell=True, stdout=PIPE, stderr=PIPE)
and this variant seems to work too:
cmd_set = ['wget', '-nv', '-O', 'dir/cpan.txt', 'http://search.span.org ']
--
HTH,
Rob
Hi Jesse.
cmd_set = ['wget', '-nv', '-O dir/cpan.txt', 'http://search.span.org ']
[snip]
>proc = Popen(cmd_set, stdout=PIPE, stderr=PIPE)
wget will treat this as
$ wget -nv '-O dir/cpan.txt' "http://search.cpan.org "
And will emit the following error because there's no pathname ' dir/cpan.txt'.
(Note the pathname has a trailing space.)
dir/cpan.txt: No such file or directory
Replace '-O dir/cpan.txt" with '-Odir/cpan.txt' or '-O', 'dir/cpan.txt'
and it should work.
Hope this helps This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Martin |
last post by:
I have a PHP script that should be run a few times a day. Currently I run
this script manually as I haven't been able to set up Lynx or wget to run it
as a cronjob. Or to be more specific: the script works, but both wget and
Lynx fail after 10 or 20 redirects, then it warns:
wget: 20 redirections exceeded.
Lynx: Alert!: Redirection limit of 10 URL's reached.
What the scripts does is download various HTML pages (allowed by the
owners)...
|
by: LRW |
last post by:
In a PHP script I have the following two lines:
$thumbproc = escapeshellcmd("wget -q -T 2000 http://(A
URL)/pa-thumbs/createthumbs.php?dir=".$order_po." &");
exec("$thumbproc 2>&1", $output);
Works perfectly...except, it always waits until it finished with the
wget before it continues in the script.
Normally this wouldn't be a problem, except this wget is calling a
page that's doing some image manipulation that can take up to two
|
by: Ken |
last post by:
How do I call c:\wget\wget.exe from a php or html file? so I can use php
variables to define the file names to download.
I want to set up wget to download several files from a server to my hard
drive so they can be used internally.
Ken
|
by: Tim Black |
last post by:
In my recent experience, popen os pipes always fail when cwd is a UNC
path. Can anyone shed any light on this? Although I've seen lots of
UNC path-related problems in this newsgroup, I've not been able to
find anything specifically about os pipes and UNC paths.
Here's a session dump that demonstrates what I'm talking about:
Python 2.3.4 (#53, May 25 2004, 21:17:02)
on win32
Type "help", "copyright", "credits" or "license" for more...
|
by: Robin Siebler |
last post by:
I have a bunch of command line tests that I need to automate. I've
run into too many bugs with the default Win2k command shell, so I need
to either purchase 4NT or handle the logic and output processing with
Python. I'm looking for experiences, comments, problems, etc.
Also, I'm trying to figure out how to use popen(). To say that the
documentation and expamples available for this is sparse would be the
understatment of the century! ...
| |
by: Michele Simionato |
last post by:
I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I
wonder why a "kill" method is missing. I am just adding it via subclassing,
class Popen(subprocess.Popen):
def kill(self, signal = SIGTERM):
os.kill(self.pid, signal)
but I would prefer to have it in the standard Popen class. I am surprised
it is not there. Any comments?
|
by: Remulac |
last post by:
I am in the process of getting ASCII data down from a server that will
print out the ASCII version of a proprietary format when you click
"get ASCII" on the site. I'm trying to bring it down programattically
so that I get an ASCII file without displaying it in a window.
So far, I've used wget from a DOS batch file, but I'm having problems
when the URL has a "%" anywhere in it. How do I escape this
character? Beyond that, is there a...
|
by: Eric_Dexter |
last post by:
I am trying to modify a programming example and I am coming up with
two problems... first is that I can't seem to pass along the
arguments to the external command (I have been able to do that with
the old module and cmd is the command I wish to try) all the output
seems to be returned as one line (at least when I run the program in
spe).
import subprocess
from os import system
cmd = """gawk -f altertime.awk -v time_offset=4 -v
|
by: Mathieu Prevot |
last post by:
Hi
it seems the script (A) finishes before the downloading ends, and the
(B) version doesn't (wanted behavior) ... this is unexpected. What
happens ?
(A) ============================================
class vid(threading.Thread):
def __init__(self):
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |