Pass Variable into CMD

8,054

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 id="Enter Rom: " 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

Share:
8,054

Related videos on Youtube

FreeSoftwareServers
Author by

FreeSoftwareServers

Check out FreeSoftwareServers.com for more information

Updated on September 18, 2022

Comments

  • FreeSoftwareServers
    FreeSoftwareServers over 1 year

    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 id="Enter Rom: "
    
    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"
    
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 6 years
      So will a user execute the script and always input the value then? I just want to make sure you need the user set variable value to be what the rest of the batch script uses, correct?
    • FreeSoftwareServers
      FreeSoftwareServers over 6 years
      No, perhaps I should have explained more, I'm looking to create a "universal" cmd that I can pass the ROM name too before running the CMD
    • FreeSoftwareServers
      FreeSoftwareServers over 6 years
      I only tested w/ User input, now I want to just have it be automated w/o user input at all
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 6 years
      Okay, so you can just make the batch script accept an argument rather than setting it and use that variable as %~1.
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 6 years
      So you can use set id=%~1 and then pass the argument to the batch as ............................................................‌​........ C:\script.cmd "Goldeneye 007.v64"
    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 6 years
      I wrote up an answer for you with more clarity so let me know what you think when you get to it.
  • FreeSoftwareServers
    FreeSoftwareServers over 6 years
    This is EXACTLY what I needed, I will do a write-up if your interested in the final "goal", is to use Steam ROM Manager to input shortcuts into steam to launch emulator w/ rom, but also I need to launch xpadder to map additional keyboar shortcuts.