Solved: Running Handbrake using a batch file

HandBrake for Windows support
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
sneaky_squirrel
New User
Posts: 1
Joined: Wed May 15, 2024 7:47 pm

Solved: Running Handbrake using a batch file

Post by sneaky_squirrel »

Description of problem or question:

Note: Someone already helped me solve my problem, and I am now sharing the solution/workaround I used for my use case for personal self-reference and to help any future users. Mad thanks to all the handsome people who helped develop this open-source software.

The Windows version of Handbrake available during the date in which this thread was created seemingly requires both:
  • .NET version 6.x.x
  • Have the Windows Environment Variable "DOTNET_ROOT" set as follows: DOTNET_ROOT=%programfiles%\dotnet
There is no problem to begin with, but I have a problematic piece of software called the "Unreal Engine" (UE_5.0) that went out of its way to overwrite the value of "DOTNET_ROOT" to point to an Unreal Engine subdirectory.

Since I did not wish to potentially break any existing functionality in the Unreal Engine, I tried to look up how to temporarily set the DOTNET_ROOT environment variable back to the default value that the HandBrake software requires (DOTNET_ROOT=%programfiles%\dotnet).

This lead to dozens of google queries and asking for help in other communities before I ultimately decided to use a Windows batch file to temporarily set DOTNET_ROOT=%programfiles%\dotnet right before launching the HandBrake application (and then have the env var value revert back to the Unreal Engine dotnet subdirectory).

Reading tutorials and documentation on batch file scripting was a big pain in the butt.


Steps to reproduce the problem (If Applicable):

Before you go around running this batch file, I recommend backing up your current value of DOTNET_ROOT in another file in case anything goes wrong.

The contents of the short batch file I wrote is the following.

setlocal
set DOTNET_ROOT=%programfiles%\dotnet
echo %DOTNET_ROOT%
"%programfiles%\HandBrake\HandBrake.exe"
timeout /t 2 /nobreak

  • "setlocal" supposedly makes all environment variable changes temporary, or local to the batch file session.
  • "set DOTNET_ROOT=%programfiles%\dotnet" makes the environment variable change.
  • "echo %DOTNET_ROOT%" prints out the value of DOTNET_ROOT, I used it to make sure the value looked correct.
  • ""%programfiles%\HandBrake\HandBrake.exe"" runs the executable. NOTE: Make sure to include the double quotes, this is because the "Program Files" path includes spaces, otherwise it might not work.
  • "timeout /t 2 /nobreak" supposedly waits 2 seconds in order to give the script time to execute all the prior commands before closing. I am unsure if this is necessary.

HandBrake version (e.g., 1.0.0):

1.7.3


Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):

Windows 10


HandBrake Activity Log ***required*** (see How-to get an activity log)

N/A, no need to fix. Workaround / Solution is provided in thread.

Code: Select all

N/A, no need to fix.  Workaround / Solution is provided in thread.
Post Reply