I’m writing a batch file for Windows and use the command 7z (7-Zip). I have put the location of it in the PATH. Is there a relatively easy way to check whether the command is available?
I’m writing a batch file for Windows and use the command 7z (7-Zip). I
Share
An attempt to execute
7z.exewill return an%errorlevel%of 9009 if the command is not found. You can check that.Note: This solution is viable for this specific
7zipuse case, and likely for plenty of others. But as a general rule, executing a command to determine whether it’s present could potentially be harmful. So make sure you understand the effect of executing the command you’re checking for, and use your discretion with this approach.