Batch Programming: Lesson 6 (Passing Variables Between Files)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello technology CRA here and welcome to episode 6 of the batch series please stay tuned and [Music] enjoy okay so today we're going to be learning how to pass variables from one batch file to another batch file and the reason why this is important because sometimes you don't want to have all your code in one batch file sometimes you like to break them into a few different batch files and you can call them and stuff but sometimes it's actually not enough to just to call them you want to pass some variables along or pass some text along and really it it adds Connection in between all the batch files so it's a fairly easy concept but incredibly important so I thought I would teach it to you guys today so I have two batch files open right here I have my send and a receive dobat and the idea we're going to be having is is taking a variable and sending it from one and and uh displaying it on the other so to start off let us uh send the variable so the way you do it is you can call the uh the batch file or you can start the batch file however you want to access it uh so in our case we're we're going to call receive uh dobat just like that and since they're in the same directory they're both on the desktop we only need to have the name of the batch file we don't need users just in desktop and uh receive. bat now if they're in different directories then we're going to have to kind of uh figure that all out but since they're both in the same directory you can just uh write the name now to send a variable all you have to do is type after it so in our case let's just send some text let's just send hi and let's save that and go over to our receive and we're going to Echo and the way we do it is percent sign one and I'll explain this here um it stores this into different variables and it does it in order so let's say we have hi here and then we type bu the very first one it detects is going to be stored into percent sign one and the second one is going to be stored into percent sign two and the next one percent sign 3 and so on and so on so you can pass multiple variables or multiple text um after each uh each uh call the the batch file so over here let's Echo um percent sign one so this is going to percent this is going to Echo high and then let's pause that and let's Echo percent sign two and then let's pause after that so what it's going to do is it's going to say hi pause and then bye and let's save both of them and let's try it so I opened up my send now it's sented over to the receive receive displayed high and now it pauses and now it says bu perfect great uh so now that we sent some text over but let's actually send some variables over so let's uh do set sorry about that uh let's do mood equals how are you so it's going to ask the user how are you and store it into the variable mood and then we'll take this and then we'll put it over to the receive batch file um and then it will display it so let's save that how are you good and it sented over and displayed back good and then over here we can do that's good oops I'm just having a hard time typing today just like that so this is going to be percent sign two since it's the second thing that it detect detects and there we go uh so let's send this how are you good I'm pressing continue that's good okay so that's cool and everything uh but here on technology crazy just like always we like to explore the possibilities of what we learned so not only can you just send text and variables you can also have this really cool thing and I I'll actually I'll show you it's easier than demonstrating um for example if I take my batch file and I drag it onto this notepad++ icon it will actually open that batch file in notepad++ and this is a feature built into many programs now we can actually do that with batch so whatever we drag on the batch file it will it will take that the the file location and then we can do whatever we want so just for example let's open up our receive here um all we have to do is it uses the same sort of uh thing of as what we just learned so let's do Echo um percent sign one uh because whatever we drag on to it is going to be stored in percent sign one and let's pause after that so now theoretically I can take this and drag it onto this and it's going to display the file's location because we have Echo percent sign one and sure enough it does now to take this a step further we can say start but this could be anything you want you can take this file location you can copy it over you can have commands that do anything with these file locations but in our case we'll just have it start I'll make sure that it's closed here drag it on to receive it took that file location and it opened it up and we can actually do that with any application now so if we take for example paint let's take paint we drag it on there and it opened up this location now that was actually a link file um that was hosted in our start menu so it opened up in CMD but you get the point it will open up that link so that's a kind of a cool thing that I thought I would show you guys today I guess that concludes this video please comment rate subscribe make sure you check out my Facebook Twitter and whatever you want to check out apparently I have Google Plus now I don't even know how to use it but uh you can check out that anyways I guess that concludes the video I hope you found this helpful and uh stay tuned to future episodes anyways that's all from technology crazy goodbye
Info
Channel: Technologycrazy
Views: 121,825
Rating: undefined out of 5
Keywords: batch, pass variables, %1, how to, lesson, technologycrazy, batch to exe converter, Batch File (File Format), Tutorial, cool batch, commands, hack, hacking, system32, windows, %2
Id: 0tQWzxxufgg
Channel Id: undefined
Length: 5min 32sec (332 seconds)
Published: Sat Oct 05 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.