| 1. |
Solve : Batch file passing parameters?? |
|
Answer» I okay I'm completely new to batch files so I need some help. I've been reading almost all the tutorials and FAQ that I've seen, however i cant find one that will answer my question. right now I'm looking at just using the openTextFile method in the script to write to the file, after the batch file has created it. I'm baffled. Maybe I'm just misreading this, but you're saying the batch file will write a file and then the script will also write to it? Why keeping shelling out to the cmd processor to create a file? Can't you use the script by opening a text file forwriting and using the FileSystemObject Writeline method? Thanks that what I was looking for!! EXCEPT how I am suppose to pass down the quotations as parameters when i;m calling the batch FORM the script. this is what I have so far in the script I get all the correct colors that represent dim's and strings but (batchFileFolder) is a var that hold the path to the where the batch file is located Code: [Select]Set WShShell = CreateObject("WScript.Shell") dim name name ="carter" dim hello hello ="Hello_World" dim number number = "5344" RetCode = WShShell.Run("""" & batchFileFolder & "myBatch.bat" &" "& name &" "& hello &" "& number"") thanksPutting quotes around strings that are quoted parameters to methods is enough to drive one to drink, so I grabbed a beer and did it the easy way. Code: [Select]strRun = batchFileFolder & "myBatch.bat " & """" & name & " " & hello & " " & number & """" WshShell.Run(strRun) When it enters the batch world it LOOKS like: ...\mybatch.bat "Carter Hello_World 5344" batchFileFolder needs to end with a backslash. One parameter is passed to the batch file as a quoted string. Use the method in the previous posts to keep or drop the quotes. I suggest you put a path on the output file in the batch code; you never know what directory the cmd window will default to. Correction to previous post: Use >> instead of > Thanks, for the help... really appreciate it.. Actually one last question? what could possibly prevent a batch file from executing when called from a script? b/c i'm actually calling a second batch from the same script, but the one that you helped me with is falling to run. however I still get a return code of zero??? but with no output file? could this then be a problem in the batch and not in the script thanks-Did the batch file actually fail to run or can you not find the output? I believe the default directory for the cmd processor is the %userprofile% value. You can override this by pointing the path of the output file in the batch code. If you could post the contents of the batch file and the console output of the batch file run, perhaps we can see where to GO next. If you're using echo to create your file, it's difficult to imagine not getting a zero return code. Quote this is what I have so far in the script I get all the correct colors that represent dim's and strings If you have some sort of a VBScript editor you may be able to step through the code and see what is happening. this is is contents of the batch file... Code: [Select]@echo off echo %~1>"C:\Inetpub\buildInstaller\batchFiles\output.txt" echo %~2>>"C:\Inetpub\buildInstaller\batchFiles\output.txt" echo %~3>>"C:\Inetpub\buildInstaller\batchFiles\output.txt" The output that I mentioned was just response.write(retCode) the second batch file that I was comparing it too was contained in the same directory and was outputting to the same destination was as this was. Both batch files were located in this directory and were outputting to the same one. this batch works fine when I call it from the START>RUN dialog just not when I call form the script. The second script is using the same WScript object and is being called after this one. thanksIt might help to know what the second batch file is doing. There are parameters to the run method which might help: Code: [Select]object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) If the second batch file needs the output of the first batch file, it may be necessary to set bWaitOnReturn to True: Code: [Select]strRun = batchFileFolder & "myBatch.bat " & """" & name & " " & hello & " " & number & """" WshShell.Run(strRun,,True) I'm still unsure why you're using batch code especially now that it appears this is ASP code. I'm also confused by the %2 and %3 parameters. The quotes indicate only one parameter was passed (%1). It might be interesting to see the console log of the batch file. |
|