| 1. |
Solve : Using the DIR function after launching a .BAT file from a Javascript? |
|
Answer» Hi, I tried running the batch file by itself and it works correctly, it's only when I launch it from Javascript that it gets mixed up. Is there a way to fix that, or is there a way to link to the .bat file's own directory with some code? I take it the folder that contains the java script your running is different from the batch file's working directory. I'd add "CD C:\path\to\batch\file\working\directory" to the top of the batch file. That way when it does the rest of code it's ALREADY in the correct location. Quote from: FausseFugue on June 25, 2008, 02:13:24 PM I'd also like to know if it's possible to send a variable from Javascript to a Batch file? Yeah, when starting the batch file add the variable to the end. "run batch_file.bat variable" (forgive my complete lack of javascript knowage!!) I believe you can add up to 3 variables this way. The batch file will see these variables as %1, %2 and %3 (in entered order) You can then use "set variable_name=%1" and so on. Hope it helps. Every batch file knows the folder where it is located (stored). This is held in a special variable %0 (read that as percent zero). You can use the normal variable modifiers so that %~dp0 is the complete drive letter and path.Quote from: Dias de verano on June 25, 2008, 03:41:48 PM Every batch file knows the folder where it is located (stored). This is held in a special variable %0 Didn't know that.... Nice one. Quote from: blastman on June 25, 2008, 04:04:15 PM Quote from: Dias de verano on June 25, 2008, 03:41:48 PMEvery batch file knows the folder where it is located (stored). This is held in a special variable %0 I made a slight error. %0 is the batch file's own FILENAME %~dpnx0 is its drive, path, filename and extension %~dp0 is its drive and path Wow, thanks a lot to you both for this quick reply, this will really help!!!Actually, I just tested and both solutions don't work. For: Quote "run batch_file.bat variable"In Javascript we use the execute command, so it normally looks like this: File("C:/Folder/File.bat").execute() so I tried: File("C:/Folder/File.bat variable").execute() but it doesn't work. It doesn't do anything, it doesn't EVEN execute the batch file. For: Quote %~dp0 is its drive and pathI tried: ECHO %~dp0 that works fine. But when I try: CD %~dp0 it doesn't work. If anyone would know a solution to those two problems I would really appreciate! Thanks!Quote from: FausseFugue on June 26, 2008, 06:56:53 AM File("C:/Folder/File.bat variable").execute() Sounds like it looking for the file "file.bat varaible" which does exist. I'd try; File(""C:\folder\file.bat " variable").execute() Pleae bear in mind I know NO JS at all! this is based on other shell script's ie, vbs Quote from: FausseFugue link=topic=60062.msg380322#msg380322 But when I try: "It doesn't work"... every help forum helper's favourite answer!!! (Not). Just how does it "not work"? try cd /d "%~dp0"Thank you both again! Quote File(""C:\folder\file.bat " variable").execute()That doesn't work in Javascript, but now I don't absolutely need that anymore since this works: Quote cd /d "%~dp0"so I can store my variables in a tmp file in the folder where the .bat file is located and use this code Code: [Select]SET /P VARIABLE=<"variable.tmp" to get the variable in the .bat file. Thank you! |
|