Search code examples
batch-filecmdbatching

How can be the variables change in other file? batch file


So here is what I need , I have two files , the first one is this: 1)

set idVendor=3edd

In the second file is this: 2)

   write /sys/class/android_usb/android0/enable 0
write /sys/class/android_usb/android0/idVendor %idVendor%
write /sys/class/android_usb/android0/idProduct 4EE2
write /sys/class/android_usb/android0/functions mtp,adb
write /sys/class/android_usb/android0/iManufacturer ${ro.product.manufacturer}
write /sys/class/android_usb/android0/iProduct ${ro.product.model}
write /sys/class/android_usb/android0/iSerial ${ro.serialno}

So I want to replace %idVendor% with 3edd , but in the other file

NOTE: the other file is not a bat file


Solution

  • The answer that I was looking for was this

    @echo off &setlocal
    set "search=%~1"
    set "replace=%~2"
    set "textfile=Input.txt"
    set "newfile=Output.txt"
    call repl.bat "%search%" "%replace%" L < "%textfile%" >"%newfile%"
    del "%textfile%"
    rename "%newfile%" "%textfile%"
    

    So thanks to myself I think lol :D