| 1. |
Solve : Batch Problem? |
|
Answer» Hi, If I correctly understand what you are attempting to achieve, the following should work: Thanks again for your post Oldun. Your close to what I'm trying to achieve, but to do it, your 4th line down would be ... ExePath=%2. Basically, the idea of ExePath is to store the executable file's location. The user can send the filelocation as an argument (%2). There is a DefaultPath in case the file location sent as %2 doesn't exist (or if the user doesn't enter a location argument). I've tried putting in your EXAMPLE (with the modification listed above) and it was still giving problems (") was unexpected at this time."). I thought it might be that you cannot set variables to argument values in this way, so I tried your example as typed... same error. I threw in a couple of ECHOs to find out thich closing bracket was the problem, and it was the final bracket. I thought it might have a problem with the nesting of brackets (for whatever reason), so I even tried it without brackets on the 4th line. Still the same error. I can't see anything wrong with the code I first put up (or yours for that matter, because it is much easier to see that your code doesn't appear to have any problems visually). At this point I have to ask, what are the chances that it's a problem with the environment itself? (As worrying as that would be).Here is the COMPLETE script. This executes without errors when I run it. Code: [Select]@ECHO OFF SetLocal SET DefaultPath="C:\Program Files\WiredRed\EPop\EPopB.exe" IF [%1]==[/?] GOTO HelpDisplay IF [%1]==[] GOTO MissingArgs IF NOT [%4]==[] ( IF [%5]==[] GOTO MissingArgs ) Set ExePath="" If Exist %DefaultPath% Set ExePath=%DefaultPath% IF Not [%2]==[] ( If Exist %2 ( Set ExePath=%2 ) ) I BUILT it from scratch starting with the code you posted. Seems to be working now for some reason. I'm even comparing it side-by-side to the amended one I tried earlier and they look the exact same WELL, thanks for your help, you certainly earned your thanks on this one. Quick question though so I at least learn something from this project. I've added code onto the end of it. Why is it that one of these works and one doesn't? Code: [Select]::Will work IF NOT %ExePath%=="" ECHO Will Run Code: [Select]::Won't work, at least for me anyway IF NOT %ExePath%=="" ( ECHO Will Run ) Rest assured I retyped it a couple of times to MAKE SURE that there were no dodgey unprintable characters that just appeared to be spaces.Did you tab that echo command batch has a heart attack when it reads a tabQuote from: mat123 on February 14, 2011, 12:45:13 AM Did you tab that echo command batch has a heart attack when it reads a tab Really? i meant when a tab is in front of a commandQuote from: mat123 on February 14, 2011, 01:11:43 PM i meant when a tab is in front of a command |
|