Pass Variable into CMD

I have setup a script and tested that it work with user input via set /p but now I want to pass that variable automatically to the cmd.

Script w/ user input:

@ECHO OFF
set /p
start /d "G:\Emulators\N64\Project64" Project64.exe "G:\Emulators\N64\Roms\%id%"

What I want to pass to the CLI:

C:\WINDOWS\system32>set id = "Goldeneye 007.v64" & "C:\script.cmd"
6

1 Answer

You can use batch arguments and pass the value of the ROM to the call of the batch script when you execute it such as C:\script.cmd "<Value Argument>".

Rather than using set /p use set id=%~1 and that's all that is needed to allow the first argument passed to the script to be used for the value to set the id variable.

Batch Script Example

@ECHO OFF
set id=%~1
start /d "G:\Emulators\N64\Project64" Project64.exe "G:\Emulators\N64\Roms\%id%"

Argument Passed to Batch Script Example

C:\script.cmd "Goldeneye 007.v64"

Further Resources

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like