![]() |
|
16 Dec 2011 | #1 |
|
Need help creating a .bat file moving output into a variable
Hello everyone,
I am looking to create a .bat file to automate task that I need to do about a thousand times. I have some experience with .bat files, however I would still consider myself a beginner. I also didn't really see a good forum for something like this so [Moderators] if it need to be moved I understand. Currently I am running windows 7 x64 SP1 on a HP pavilion a1657c. I am using this program http://www.makemkv.com/developers/usage.txt and with the command "makemkvcon -r info" will get an output of my DVD drive that looks like this Code:
C:\>makemkvcon -r info MSG:1005,0,1,"MakeMKV v1.6.16 win(x86-release) started","%1 started","MakeMKV v1 .6.16 win(x86-release)" MSG:1004,0,1,"Debug logging enabled, log will be saved as C:/MakeMK V_log.txt","Debug logging enabled, log will be saved as %1","C:/Mak eMKV_log.txt" DRV:0,1,1,1,"DVD+R-DL HL-DT-ST DVD-RAM GH22NP20 1.04","HOLIDAY_MOVIES_1","\\Device\\ CdRom0" DRV:1,0,0,0,"","","" DRV:2,0,0,0,"","","" DRV:3,0,0,0,"","","" DRV:4,0,0,0,"","","" DRV:5,0,0,0,"","","" DRV:6,0,0,0,"","","" DRV:7,0,0,0,"","","" DRV:8,0,0,0,"","","" DRV:9,0,0,0,"","","" DRV:10,0,0,0,"","","" DRV:11,0,0,0,"","","" DRV:12,0,0,0,"","","" DRV:13,0,0,0,"","","" DRV:14,0,0,0,"","","" DRV:15,0,0,0,"","","" Use: makemkvcon [switches] Command [Parameters] Commands: info <source> prints info about disc mkv <source> <title id> <destination folder> saves a single title to mkv file stream <source> starts streaming server backup <source> <destination folder> backs up disc to a hard drive Source specification: iso:<FileName> - open iso image <FileName> file:<FolderName> - open files in folder <FolderName> disc:<DiscId> - open disc with id <DiscId> (see list Command) dev:<DeviceName> - open disc with OS device name <DeviceName> Switches: -r --robot - turn on "robot" mode, see http://www.makemkv.com/developer s Thank you for any help you can give me even if it is just a link to another web site with help in creating bat files. I posted to sevenforums as I have gotten a lot of help with windows 7 in the past (the tutorials are really good). -S |
My System Specs![]() |
. |
|
16 Dec 2011 | #2 |
|
Direct cut/paste from working .bat script....
You have to delete all the leading .. that I added so it would indent correctly to be readable. *********************************************** @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION REM for testing, I used a static variable here REM if cut/pasting this be sure to rejoin these 2 lines to make them 1 line SET var0=DRV:0,1,1,1,"DVD+R-DL HL-DT-ST DVD-RAM GH22NP20 1.04","HOLIDAY_MOVIES_1","\\Device\\CdRom0" REM process each line of output from command REM You will replace ("!var0!") below with ('your command') FOR /F "TOKENS=*" %%a IN ("!var0!") DO ( ..REM save in local variable for easier complex DOS script lines ..SET vara=%%a ..REM parse 1st value before first colon for this output line ..FOR /F "TOKENS=1 DELIMS=:" %%f IN ("!vara!") DO ( ....REM if drv then we have something to examine ....IF /I %%f == drv ( ......REM replace double-quote with @ for parsing ......SET varanq=!vara:"=@! ......REM get 1st chunk after first @ ......FOR /F "TOKENS=2 DELIMS=@" %%h IN ("!varanq!") DO ( ........SET var=%%h ........REM parse 3 bytes from beginning which is just after @ ........SET var2=!var:~0,3! ........REM DVD? note slashI option to ignore case ........IF /I !var2! == dvd ( ..........REM parse 6th chunk comma-delimited ..........FOR /F "TOKENS=6 DELIMS=," %%t IN ("!varanq!") DO ( ............REM now remove @s on each end ............FOR /F "TOKENS=1 DELIMS=@" %%y IN ("%%t") DO ( ..............SET mydir=%%y ..............ECHO final !mydir! ............) ..........) ........) ......) ....) ..) ) |
My System Specs![]() |
16 Dec 2011 | #3 |
|
Thanks for the quick reply. So I copied this into a bat file and get an error. Maybe I copied it incorrectly or should put it into the bat file differently?
Here is my bat Code:
::mkvbat Path="C:\Program Files (x86)\MakeMKV" makemkvcon -r info FOR /F %%a IN ('makemkvcon -r info') DO ( REM save in local variable for easier complex DOS script lines ..SET vara=%%a ..REM parse 1st value before first colon for this output line ..FOR /F "TOKENS=1 DELIMS=:" %%f IN ("!vara!") DO ( ....REM if drv then we have something to examine ....IF /I %%f == drv ( ......REM replace double-quote with @ for parsing ......SET varanq=!vara:"=@! ......REM get 1st chunk after first @ ......FOR /F "TOKENS=2 DELIMS=@" %%h IN ("!varanq!") DO ( ........SET var=%%h ........REM parse 3 bytes from beginning which is just after @ ........SET var2=!var:~0,3! ........REM DVD? note slashI option to ignore upper/lower case ........IF /I !var2! == dvd ( ..........REM parse 6th chunk comma-delimited ..........FOR /F "TOKENS=6 DELIMS=," %%t IN ("%%p") DO ( ............REM now remove @s on each end ............FOR /F "TOKENS=1 DELIMS=@" %%y IN ("%%t") DO ( ..............SET mydir=%%y ............) ..........) ........) ......) ....) ..) ) Code:
C:\Users\Kira\Desktop>makemkvcon -r info MSG:1005,0,1,"MakeMKV v1.6.16 win(x86-release) started","%1 started","MakeMKV v1 .6.16 win(x86-release)" MSG:1004,0,1,"Debug logging enabled, log will be saved as C:\\Users\\Kira/MakeMK V_log.txt","Debug logging enabled, log will be saved as %1","C:\\Users\\Kira/Mak eMKV_log.txt" DRV:0,1,1,1,"DVD+R-DL HL-DT-ST DVD-RAM GH22NP20 1.04","HOLIDAY_MOVIES_1","\\Device\\ CdRom0" DRV:1,0,0,0,"","","" DRV:2,0,0,0,"","","" DRV:3,0,0,0,"","","" DRV:4,0,0,0,"","","" DRV:5,0,0,0,"","","" DRV:6,0,0,0,"","","" DRV:7,0,0,0,"","","" DRV:8,0,0,0,"","","" DRV:9,0,0,0,"","","" DRV:10,0,0,0,"","","" DRV:11,0,0,0,"","","" DRV:12,0,0,0,"","","" DRV:13,0,0,0,"","","" DRV:14,0,0,0,"","","" DRV:15,0,0,0,"","","" Use: makemkvcon [switches] Command [Parameters] Commands: info <source> prints info about disc mkv <source> <title id> <destination folder> saves a single title to mkv file stream <source> starts streaming server backup <source> <destination folder> backs up disc to a hard drive Source specification: iso:<FileName> - open iso image <FileName> file:<FolderName> - open files in folder <FolderName> disc:<DiscId> - open disc with id <DiscId> (see list Command) dev:<DeviceName> - open disc with OS device name <DeviceName> Switches: -r --robot - turn on "robot" mode, see http://www.makemkv.com/developer s DO was unexpected at this time. C:\Users\Kira\Desktop>..FOR /F "TOKENS=1 DELIMS=:" %f IN ("!vara!") DO ( -S |
My System Specs![]() |
. |
|
16 Dec 2011 | #4 |
|
Checking...
Replaced 2nd post in and fixed variable bug..... You have to delete all the leading .. that I added so it would indent correctly to be readable. |
My System Specs![]() |
16 Dec 2011 | #5 |
|
Thank you again. So I will cut and past this into my bat and give it a try. I'll remove all the ....
One thing about this line SET var0=DRV:0,1,1,1,"DVD+R-DL HL-DT-ST DVD-RAM GH22NP20 1.04","HOLIDAY_MOVIES_1","\\Device\\CdRom0" The HOLIDAY_MOVIES_1 is the title of the DVD, so if I run this bat against another DVD that is not titled HOLIDAY_MOVIES_1 will this var0 be set correctly? (I will past the line together when I cut and paste) Your time is much appreciated. -S |
My System Specs![]() |
16 Dec 2011 | #6 |
|
Thank you again. So I will cut and past this into my bat and give it a try. I'll remove all the ....
One thing about this line SET var0=DRV:0,1,1,1,"DVD+R-DL HL-DT-ST DVD-RAM GH22NP20 1.04","HOLIDAY_MOVIES_1","\\Device\\CdRom0" The HOLIDAY_MOVIES_1 is the title of the DVD, so if I run this bat against another DVD that is not titled HOLIDAY_MOVIES_1 will this var0 be set correctly? (I will past the line together when I cut and paste) Your time is much appreciated. -S ALL LEADING .. removed. You can REMOVE the whole var0 line. I simply had that in in case you wanted to test MY script prior to changing that one FOR line and inserting ('YOUR COMMAND') line syntax. IOW, I can't test your command as I don't have access to it. At the bottom, for EACH line that has DRV: something, the 6th comma-delimited field that has "" around it will be placed in the variable mydir. You could then, at that point in the code, add something like this for example: MKDIR D:\mymovies\!mydir!\ This would create a directory called D:\mymovies\HOLIDAY_MOVIES_1\ Or whatever you want to do with the parsed value.... |
My System Specs![]() |
16 Dec 2011 | #7 |
|
WOW! That worked! I know that this is really simple coding, but I am totally amazed when something like this works. It is like magic. Thanks for the help. I tried it and it printed at the bottom of the CMD window final HOLIDAY_MOVIES_1. That totally proved to me that it took that info from the DVD and parsed it out correctly into the %%y variable which gets set into mydir at the end.
So if I understand this process now, I need to replace var0 with the command that generated the info for which the code you made will check. Does that sound right? I've tried several different things in the "!var0!" spot and none of them seem to do what happens when I set the variable in the beginning. -S |
My System Specs![]() |
16 Dec 2011 | #8 |
|
WOW! That worked! I know that this is really simple coding, but I am totally amazed when something like this works. It is like magic. Thanks for the help. I tried it and it printed at the bottom of the CMD window final HOLIDAY_MOVIES_1. That totally proved to me that it took that info from the DVD and parsed it out correctly into the %%y variable which gets set into mydir at the end.
So if I understand this process now, I need to replace var0 with the command that generated the info for which the code you made will check. Does that sound right? I've tried several different things in the "!var0!" spot and none of them seem to do what happens when I set the variable in the beginning. -S |
My System Specs![]() |
16 Dec 2011 | #9 |
|
RIGHT ON!!! Now it is working perfectly. Thanks again and please let me know what I need to do so that you get some good will your way.
I just wanted to show what was the final product of all your hard work. Now all I have to do is link it with the autoplay when a disk is inserted and I should be able to fly through these things. Thanks -S Code:
::mkvbat @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION REM process each line of output from command REM You will replace ("!var0!") below with ('your command') Path="C:\Program Files (x86)\MakeMKV" FOR /F "TOKENS=*" %%a IN ('makemkvcon -r info') DO ( REM save in local variable for easier complex DOS script lines SET vara=%%a REM parse 1st value before first colon for this output line FOR /F "TOKENS=1 DELIMS=:" %%f IN ("!vara!") DO ( REM if drv then we have something to examine IF /I %%f == drv ( REM replace double-quote with @ for parsing SET varanq=!vara:"=@! REM get 1st chunk after first @ FOR /F "TOKENS=2 DELIMS=@" %%h IN ("!varanq!") DO ( SET var=%%h REM parse 3 bytes from beginning which is just after @ SET var2=!var:~0,3! REM DVD? note slashI option to ignore case IF /I !var2! == dvd ( REM parse 6th chunk comma-delimited FOR /F "TOKENS=6 DELIMS=," %%t IN ("!varanq!") DO ( REM now remove @s on each end FOR /F "TOKENS=1 DELIMS=@" %%y IN ("%%t") DO ( SET mydir=%%y ECHO final !mydir! MKDIR D:\mymovies\!mydir!\ makemkvcon mkv disc:0 all D:\mymovies\!mydir!\ |
My System Specs![]() |
16 Dec 2011 | #10 |
|
Good deal. Your question was very topical as I only wrote my first .bat script 2 weeks ago. Having programmed since 1977 with a dozen languages and 4 different hardware platforms, the DOS syntax was simply...unbelievably cryptic. So, now that my System Image (see the backup and restore forum) .bat is complete, I jumped on having a chance to help someone else who is new to .bat. And that Sys. Image .bat had some tricky stuff to a newbie.
|
My System Specs![]() |
![]() |
Thread Tools | |
Similar help and support threads | ||||
Thread | Forum | |||
How I read a file .txt and put the last line in a variable People, I am from Brazil. My English is not very well! Sorry. I need read a file .txt, where, I need put the last line in a variable. I am tryng find de number of lines and with a FOR /F read line and line. But not this going right. @echo off setlocal enableextensions... |
General Discussion | |||
BULK creating of folders based on file names, and then moving files in Hi Everyone, i have been looking for weeks for a way to do this and i have tried so many applications but i just cant seem to get it right, i was hoping that you guys my be able to help me out here with this one.. i have two folders, at the moment with identical file names in the ( they... |
General Discussion | |||
Can a property from a .properties file be made into a usable variable? I have code to read out lines from .properties, but it just prints it out, because im an idiot and didn't notice till now. So, the question is, can it be made into a variable instead? current code; Properties prop = new Properties(); InputStream input = null; try { input = new... |
Software | |||
.bat file, batch coding simple variable use @echo off color C SET IPaddress=0 set /p IPaddress=Please enter the destination Ip Address: color A ping IPaddress pause okay, so i want the IPaddress variable to be used as the ipaddress to be pinged. When i run this, it is ineffective. Can someone teach me as why and how to properly code... |
Software | |||
Problem with User Profiles (Creating, Moving) Okay so I've got a challenging problem. I didn't know where I could find help and then I remembered the forum here and signed up... So a long time ago (I barely remember how except I went to the registry) I moved my User folder from my SSD Drive C:\User\Username to my hardrive under just... |
General Discussion |
Our Sites |
Site Links |
About Us |
Find Us |
Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd All times are GMT -5. The time now is 15:15. |
![]() ![]() ![]() ![]() ![]() |