This is great stuff...thanks guys. I still haven't been able to get the results I want though. When I first started on this project, I was simply passing single element variables to MyScript.bat (i.e. MyScript.bat Var1 Var2 Var3...). A new requirement to handle multi-element variables threw that out the window though.
To put this command in a real world context, I have a SQL job that's sending the following command line to a script that schedules the command specified in -Script as a task on a remote server.
xp_CMDSHELL Path\MainScript -Server Server1 -Name Task_Name -Script MyScript.bat /Arg1 xyz /Arg2 abc /Arg3 tuv def lmn /Arg4 Last Arg
The arguments prefaced with the "-" are used by MainScript while the arguments prefaced with the "/" are used by MyScript. Some arguments in MyScript.bat contain spaces and have an undefined number of elements, seen in /Arg3 and /Arg4 above. That's the task that gets scheduled.
So, within MyScript.bat, I need to set the internal variables with the arguments passed to it. Since I don't know how many elements are in an argument, I can't simply assign variable names to each argument. If the arguments were only a single word, using the commandline above, I would just:
Code: Select all
...but this doesn't work with /Arg3 and /Arg4. And, I can't seem to get this working with jaffamuffin's script either (that's a great script BTW). Any more ideas?