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
Related
I have over 1000 audio files, all of which end in a mouse click. I would like to remove the last half second from all of them. The audio files have different length (i.e. 15sec, 5 sec ...) But one thing in common with all of them is the last half second has a mouse click sound. How do I trim in bulk the ending of the mp3 files within a folder using windows 10 command line? I already have FFMPEG downloaded. Thank you!
This is two questions in one:
How to remove the last 0.5 seconds from inputs of arbitrary durations?
How to incorporate this into a Windows batch script?
I'll answer #1 because I'm not a Windows user. The batch scripting will be up to you.
Get duration using ffprobe:
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp3
Trim using ffmpeg:
ffmpeg -i input.mp3 -t <duration> -c copy output.mp3
Replace <duration> with the output from ffprobe minus 0.5 seconds.
How to incorporate this into a Windows batch script?
This should do:
FOR %%A IN (*.mp3) DO (
FOR /F %%B IN ('ffprobe.exe -v error -show_entries format^=duration -of csv^=p^=0 "%%~A" ^| xidel -s - -e ". - 0.5"') DO (
ffmpeg.exe -i "%%~A" -t %%B -c copy "%%~dpnA_trimmed.mp3"
)
)
First of all, doing floating point calculations in Batch is officially impossible and unofficially really hard to script. That's why I suggest to let Xidel do the math. It's first of all a command line tool to download and extract data from HTML/XML/JSON, but it can do A LOT more!
Loop over all mp3-files in the current directory.
The ffprobe command as suggested by llogan piped to Xidel to subtract the 0.5s. For example, 25.547755 now becomes 25.047755.
Don't forget to escape the necessary characters inside the for-loop! The = and | in this case.
The ffmpeg command as suggested by llogan, which opens "%%~A (the mp3-file), sets the duration to %%B and creates a new mp3-file (<filename>_trimmed.mp3).
This code assumes the mp3-files, ffprobe.exe, xidel.exe and ffmpeg.exe are all in the same directory.
I am trying to set up a batch file to get webpage download time using curl command and export to CSV or text file.
I am using the following curl command:
curl http ://myurl.com -w %{time_total}\n -o NUL -s
The command above works when using it in cmd and will provide a response ex - 0.188000.
However, when I am using the command via a batch file and try to export using the following, it does not work. Instead of .1888000, I get {time_total}.
#echo on
ECHO.
totaltimeresponse
ECHO.
SET PATH=%PATH%;C:\software\curl
ECHO.
curl http ://myurl.com -w %{time_total}\n -o NUL -s >> total-time.txt
ECHO.
This is my first time working with curl and batch files, so I am not sure what is happening. I have researched and researched, but I still don't know what wrong I have made.
Any ideas or suggestions?
I don't have a Windows machine to test, but try this --should work.
#echo on
ECHO.
totaltimeresponse
ECHO.
SET PATH=%PATH%;c:\software\curl
ECHO.
curl http ://myurl.com -w %%{time_total}\n -o NUL -s >> total-time.txt
ECHO.
Currently, the following code in a batch file works: it runs all SQL scripts in %SCRIPTFOLDER% and sends each script's output to a CSV within the same folder as the scripts.
FOR /F "tokens=*" %%S IN (
'DIR /B "%SCRIPTFOLDER%\*.sql" '
) DO (
sqlcmd -b -S %INSTANCE% -d %DATABASE% -i "%%~fS" -s "|" -o "%%~dpnS.csv" -W
IF ERRORLEVEL 1 GOTO errorhandling
ECHO %%~nS.csv successfully created
)
What I'd like to do is allow the user to specify where the generated CSVs get sent to using a variable %OUTPUTFOLDER%.
I tried placing %OUTPUTFOLDER%, which is a full path, drive, and folders (e.g. D:\some folder\output) in various positions within %%~dpnS.csv. Specifically,
%%~dp%OUTPUTFOLDER%nS.csv
and
%%~dpn%OUTPUTFOLDER%S.csv
but they didn't work and I'm (probably obviously to you) woefully inept at batch file syntax!
I understand that dp is the drive and path and that S is the file name, but I'm not sure how to integrate that with a the variable that is the path.
The iterating variable is %%S, the modifier ~dpn forces an evaluation of drive path and name.
In this case you want to specify the drive and path yourself so depending on wether %OUTPUTFOLDER% has a trailing backslash
-o "%OUTPUTFOLDER%%%~nS"
or not use:
-o "%OUTPUTFOLDER%\%%~nS"
Does anyone have any idea on how to force dumpcap to create the directory before it writes in it? I am trying to capture packets for a year, and have a batch file that writes based on the year/month/day/hour, but unfortunately dumpcap doesn’t try and create the directory if it is not there.
Any suggestions?
dumpcap -i 2 -b duration:3600 -P -w D:\pcaps\%year%\%month%\%day%\%HH24%\capture -q
Any help would be appreciated.
(I know I could create all the directories ahead of time, or run it every hour with at/schtasks and create the directory beforehand. Looking for another way.)
Additionally, I found another workaround (This will store the files by hour and I just have a schtask that runs it each hour):
#echo off
For /f "tokens=1-4 delims=/:." %%a in ("%TIME%") do (
SET HH24=%%a
SET MI=%%b
SET SS=%%c
SET FF=%%d
)
mkdir d:\pcaps\%year%
mkdir d:\pcaps\%year%\%month%
mkdir d:\pcaps\%year%\%month%\%day%
mkdir d:\pcaps\%year%\%month%\%day%\%HH24%
"c:\program files\wireshark"\dumpcap -i 2 -a duration:3600 -b filesize:100000 -P -w D:\pcaps\%year%\%month%\%day%\%HH24%\CORP.pcap -q
Does anyone have any idea on how to force dumpcap to create the directory before it writes in it?
No, because there is no way to do that; dumpcap never calls any routines that create a directory for the capture file. The only way to force it to do so would be to change it to do so and recompile it.
I would like to have a bat file find a specific file within a directory and have it update the time stamp to be current and or synched with the time of activating the bat file.
You don't need to use "touch.exe" to accomplish this. A simple script like this will prove the case:
#echo off
ECHO Test1:
SET FILENAME=test.xml
copy /b %FILENAME% +,,
dir %FILENAME%
timeout 64
ECHO Test2:
copy /b %FILENAME%,,+
dir %FILENAME%
pause
This proves that there are 2 different ways to do this, syntactically.
Can you use touch (already suggested in Jubjub Bandersnatch's comment):
change the modification time from all TXT files to now:
touch -m *.txt
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.
-a change only the access time
-c do not create any files
-d, --date=STRING parse STRING and use it instead of current time
-f (ignored)
-m change only the modification time
-r, --reference=FILE use this file's times instead of current time
-t STAMP use MMDDhhmm[[CC]YY][.ss] instead of current time
--time=WORD access -a, atime -a, mtime -m, modify -m, use -a
--help display this help and exit
--version output version information and exit
STAMP may be used without -t if none of -drt, nor --, are used.
I ended up using:
copy Certain.config,,+
TIMEOUT 2
net stop Certain_Services
TIMEOUT 1
net start Certain_Services
it will update the Modified Date, stop and restart the services.