質問

I have a problem with my batch command line, which is :

for /l %%X in (1, 1, 100) do wget      --background -q --no-check-certificate -O ->>donnees_wget "https://aaaa/%%X"

the "->>" allows to append to one file all the downloads.

I can not use background(--background) and saving in output(-O) file together and I don't understand that. My error message is "the processus can not access to the file because it's used by another processus"

Has anyone an idea about the problem?

thanks a lot

役に立ちましたか?

解決

>> is not handled by wget, but cmd. Each time you start a wget process, you are asking cmd to sent the output of this command to the file, but you can not have two processes redirecting its output to the same file at the same time (not it batch scripts)

So, the only way to do what you are indicating is start only one instance of wget, that will go to background to do its work, adding all the output to the same file.

To get this, you will need to generate a temporary file where to store the urls to be processed by wget.

@echo off

    set "tempFile=%temp%\wgetTest"
    (for /l %%X in (1 1 5) do (
        echo(https://aaaa/%%X
    ))>"%tempFile%"

    wget -i "%tempFile%" --background --no-check-certificate -o wget.log -O donnees_wget 

If --background is not used (which detaches the wget process from the console), instead of generating a temporary file, the generated list can be piped into wget, using - (stdin) as the file from where the urls are to be retrieved

@echo off

    set "tempFile=%temp%\wgetTest"
    (for /l %%X in (1 1 5) do (
        echo(https://aaaa/%%X
    )) | wget -i - --no-check-certificate -o wget.log -O donnees_wget 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top