Pass variable from one batch file to another




















And to use param1 in a safe way, enable the delayed expansion. KevinEdwards I tested it, test. Only test. Ah, yes, a caret doesn't escape it properly. You need quotes, which is feasible for all the use cases I've come across. I just wanted to pass it along. Thanks for testing it! Cheers : — Kevin Edwards. Show 4 more comments. Frank Krueger Frank Krueger SteveMidgley I upvoted your comment probably a year or so ago. I then promptly forgot about it and just today I was trying and staring confusingly at my for loop in the command line and wondering why it farted and did nothing else.

So here's another virtual upvote from me. I'll be back in another year or so when I hit the same issue again. We usually reserve the digits for command line processing and the double percent only applies to the for statement as far as I know. The answer is wrong. There is no need to complicate it. Peter Mortensen DearWebby DearWebby 4 4 silver badges 2 2 bronze badges. USAGE: test. The Godfather The Godfather 9 9 silver badges 16 16 bronze badges.

True enough, but it barely touches the subject matter. Let's keep this simple. Here is the. Love and peace - Joe Codeswell Love and peace - Joe Codeswell 2, 3 3 gold badges 36 36 silver badges 45 45 bronze badges. Amr Ali Amr Ali 1, 14 14 silver badges 10 10 bronze badges. But fails with many different arguments, like test. For example, given the following command: myscript. Evan Kennedy Evan Kennedy 3, 1 1 gold badge 22 22 silver badges 30 30 bronze badges.

Been looking at using this method as I would like to pass arguments into a batch file in this manner. However I notice that after the variables are set, even after exiting the batch file the parameters are still set in the cmd if accessed and the batch has ended, they are not restored to their previous state. Should this method handle that situation?

On topic and better than some of the rest of the answers on this thread. There are a ton of great tools and solutions out there and you might already have access to some without paying for anything else.

Something like:. Many more resources out there as well. Setx will set the environment variable, but only starting a new cmd will load them. So, instead of Call script. Learning PowerShell is on my list of things to do but after this experience, I may bump it up to the top of the list. I'll check out the links you posted!

To continue this discussion, please ask a new question. Which of the following retains the information it's storing when the system power is turned off? Submit ». Get answers from your peers along with millions of IT pros who visit Spiceworks. Hello Spiceheads! You could also set the path as a system variable to make it global but that is like using an Indy race car to go to the grocery store. I can probably combine the scripts, I haven't done so out of my own stubbornness.

The second script installs some software that is pointed to a test environment. When we go live with this software and upgrade production, I was hoping that I could just change the last line of the batch file to point to a new installation batch script. I want to be able to push this out to about 60 PC's on the domain to cut down on the This is what I was thinking I was going to have to attempt. Passing the variable 'manually' between the scripts. What really has me stumped is that it is a system variable.

When the first batch script ends, the second one kicks off and the installation fails. I can go into the environment variables and SEE the variable the first batch script sets. I've also confirmed that all the installation directories are spot on. Seriously though, I would ditch batch scripts and learn a bit of PowerShell. It actually isn't that hard to pick up how to do simple stuff like this in it. I spend a couple of hours today figuring out how to get the result from a DOS batch as a variable in another DOS batch file.

Here is the solution I came up with:. My original called batch file calculated yesterdays date.



0コメント

  • 1000 / 1000