What is the proper way to test if a parameter is empty in a batch file?
Use square brackets instead of quotation marks: IF [%1] == [] GOTO MyLabel Parentheses are insecure: only use square brackets.
Use square brackets instead of quotation marks: IF [%1] == [] GOTO MyLabel Parentheses are insecure: only use square brackets.
An easy way to replace the touch command on a windows command line like cmd would be: type nul > your_file.txt This will create 0 bytes in the your_file.txt file. This would also be a good solution to use in windows batch files. Another way of doing it is by using the echo command: echo.> … Read more
Command line usage: for /f %f in (‘dir /b c:\’) do echo %f Batch file usage: for /f %%f in (‘dir /b c:\’) do echo %%f Update: if the directory contains files with space in the names, you need to change the delimiter the for /f command is using. for example, you can use the … Read more
You can do and with nested conditions: if %age% geq 2 ( if %age% leq 12 ( set class=child ) ) or: if %age% geq 2 if %age% leq 12 set class=child You can do or with a separate variable: set res=F if %hour% leq 6 set res=T if %hour% geq 22 set res=T if … Read more
Use the SC (service control) command, it gives you a lot more options than just start & stop. DESCRIPTION: SC is a command line program used for communicating with the NT Service Controller and services. USAGE: sc <server> [command] [service name] … The option <server> has the form “\\ServerName” Further help on commands can be … Read more
You can also select your default terminal by pressing F1 in VS Code and typing/selecting Terminal: Select Default Profile (or Terminal: Select Default Shell in older VSCode versions). Older:
Use cd with no arguments if you’re using the shell directly, or %cd% if you want to use it in a batch file (it behaves like an environment variable).
Issues blak3r / Rushyo’s solution works fine for everything except Windows 8. Running AT on Windows 8 results in: The AT command has been deprecated. Please use schtasks.exe instead. The request is not supported. (see screenshot #1) and will return %errorLevel% 1. Research So, I went searching for other commands that require elevated permissions. … Read more
You can use the more command. For example: more filename.txt Take a look at GNU utilities for Win32 or download it:
One way is: application arg0 arg1 > temp.txt set /p VAR=<temp.txt Another is: for /f %%i in (‘application arg0 arg1’) do set VAR=%%i Note that the first % in %%i is used to escape the % after it and is needed when using the above code in a batch file rather than on the command … Read more