batch-file

Batch function not working correctly

此生再无相见时 提交于 2021-01-29 18:28:40
问题 A while ago I made a function that you can call from the command prompt or any batch file (it was just for fun, I don't see how it could be useful). It basically just makes your (Microsoft) computer speak whatever you wrote in as the parameter. I recently got some inspiration to add a switch to it where it would read the contents of a file. My standalone script worked, but when I added it to my function, it didn't work as I would have liked. Here's the code: @echo off & setlocal

PostgreSQL uninstall on Windows

[亡魂溺海] 提交于 2021-01-29 18:03:21
问题 In the process of upgrading from PostgreSQL 11 to 12 on Windows, I uninstall PG-11 using the uninstall.exe, wait for like 15 seconds (to make sure that the uninstall.exe is complete), delete the bindir (if exists) and then install the Postgres-12.exe. This all is done in a batch file and the code looks something like: uninstall-postgresql.exe --mode unattended PING 1.1.1.1 -n 15 >NUL if exist C:\PostgreSQL\bindir RD /Q /S C:\PostgreSQL\bindir postgresql-12.1.exe --servicename Postgres -

Batch: Taskkill timeout without waiting for timer

我怕爱的太早我们不能终老 提交于 2021-01-29 17:53:30
问题 I'm writing a batch script which runs a few programs. As each program finishes what it's doing it waits for either the user to close it out, moving on to the next, or being closed by taskkill after a timeout of so many seconds. If I consider the main script as MAIN, the program as TASK and the timer as KILLER. The MAIN starts the TASK and KILLER at (about) the same time. TASK does what it's supposed to and KILLER waits 600 seconds before killing TASK. However if TASK were closed by the user

Including/excluding files from batch script

…衆ロ難τιáo~ 提交于 2021-01-29 13:24:02
问题 In the following batch script for copying the most recently created files from a directory, I would like to include and exclude specific file names, but not sure how to. @echo off set source="C:\FolderA\FolderB" set target="C:\FolderC\FolderD" FOR /F "delims=" %%I IN ('DIR %source%\*.* /A:-D /O:-D /B') DO COPY %source%\"%%I" %target% & echo %%I & GOTO :END1 :END1 ... set source="C:\FolderE\FolderF" <--- From this directory I would also want to copy, in addition to the most recent file created

How to toggle 'Use Automatic Configuration script' checkbox in IE settings without clearing the proxy URL?

丶灬走出姿态 提交于 2021-01-29 11:51:02
问题 I need to switch on the proxy to use internet and switch it off for office intranet. Manually it is tiresome. The proxy does not change. How to just toggle the check box using bat file? If the status is enabled it will disable and if disable it will enable. Nothing much. Don't want to clear the proxy string. Just enabling/disabling the checkbox. 回答1: As far as I know, generally, toggle the 'Use Automatic Configuration script' checkbox will not clear the proxy server address. But it might

Run bat files in parallel and wait until they are finished before run new set of bat files

吃可爱长大的小学妹 提交于 2021-01-29 10:09:25
问题 I have a series of bat files that I want to run in parallel, for example: start program1_1.bat start program1_2.bat start program1_3.bat wait until program1 finished then start program2_1.bat start program2_2.bat start program2_3.bat wait until program2 finished then ... So far, what I've tried is this function: :waitForFinish set counter=0 for /f %%i in ('tasklist /NH /FI "Imagename eq cmd.exe') do set /a counter=counter+1 if counter GTR 2 Goto waitForFinish But it just launched the first 3

Passing a variable in batch file to another batch file with FOR loop to process list of folders

不打扰是莪最后的温柔 提交于 2021-01-29 09:10:48
问题 I Have a list of folders on DVD that I would like to process one at a time. I am trying to use a FOR command to pass through information to set as the variable in a 2nd batch file. I am having the user input two variables, then I'd like a 3rd variable to come from my list of folders. Then run a 2nd batch file for each folder on the DVD: echo enter Drive letter set /p Drive= echo enter diskname set /p diskname= FOR /F %%i IN ('dir /ad /b e:\') DO set book=%%i call Load.bat %drive% %diskname%

batch script echo dynamic variable [duplicate]

狂风中的少年 提交于 2021-01-29 08:53:55
问题 This question already has answers here : How would I call a dynamic variable name? (1 answer) Return Values of Recursive Dynamic Variables in Batch (2 answers) Arrays, linked lists and other data structures in cmd.exe (batch) script (10 answers) How to change the name of an environment variable with a different variable? (2 answers) Closed 2 years ago . I have a dynamic variable in my batch script and I need to use it or print it later on in the script, for example set txt1=hello world echo

Set a return value as variable in window batch

僤鯓⒐⒋嵵緔 提交于 2021-01-29 08:14:08
问题 How can I use if else statement to echo if value more than 1? @echo off setlocal set "sql=c:\xampp\mysql\bin\mysql.exe" for /f "usebackq" %%a in (`%sql% -u root -ss -e "select COUNT(*) FROM mytable" mydatabase`) do set TESTVAR=%%a if %TESTVAR% GEQ 1 (echo Database has already existed.) else echo import pause 回答1: Kind of like this: @echo off setlocal set "sql=c:\xampp\mysql\bin\mysql.exe" for /f "usebackq" %%a in (`%sql% -u root -ss -e "select COUNT^(*^) FROM browser" form_generator`) do set

Running two command prompt terminals in native windows, how can I redirect the output of one to the input of the other?

ぃ、小莉子 提交于 2021-01-29 08:04:04
问题 I have one Windows 10 command prompt running and awaiting input, and I wish to automate continuous and live input with a second command prompt. I have gotten the second command prompt to extract the desired variable, and I wish to send it to the other command prompt that is waiting for input. The "awaiting input" command prompt must run in real time because it is connected to Plink (not an SSH session so no use of the -m command here) which is connecting to a microcontroller. So it cannot be