This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 6151. |
Solve : XP pro DOS batch file editing? |
|
Answer» ghostdog74 you are a star! An observation is that although this vb script version avoids trailing spaces, my impression is that the process runs more slowly than the all batch file version.yes, that's because of the algorithm that is looping over the file. Its not efficient. Its left to you to find out why and improve on it if you are interested. Also, once you become more familiar with vbscript, you will be able to do all in one script, without going through the batch for loop...i guess that would be a bit faster...well....Hi Sidewinder, Thanks for taking another look. The problem I have now is that even with the space removed as you show below I still get an addiitional space on all the unedited lines! Quote from: Sidewinder on June 07, 2007, 04:54:09 AM Code: [Select] echo !input!>> %%x.chg In my adapted version of your original code I did remove all the spaces between input! and the > in the initial belief that this would fix it but it didn't. This bit as shown below is taken from my earlier post above: if %%i==%1 echo !input1!>> %%x.chg if not %%i==%1 ( if not "%%j"=="" echo %%i,%%j>> %%x.chg ) if not %%i==%1 ( if "%%j"=="" echo %%i>> %%x.chg ) Before I did this there were two extra spaces added to the ends of the lines when they were written out again! (The reason for the if statements is to prevent other occurrences of 60.0 in the file being changed too. I forgot to mention this in my first post)! It is a weirdy. Microsoft would probably say, "How could you possibly not want it to work this way"! Regards, Les. Les, I was able to get this to work on XP Home, but on a XP Pro rig, the batch file created the extra space. You may CALL this weirdy but Microsoft would call it a feature. I have no answer to this other than to suggest you go with the Ghostdog solution of a VBScript. In the long run VBScript is a richer language, less cryptic, more intuitive and provides more functionality for complex situations than does batch code. For more info on scripting in Windows check out the Script Center. Good luck. Sidewinder, Ghostdog, Contrex, What can I say other than thanks again for all the help and advice it is much appreciated. I can live with the time it takes the batch file/vb combination to make the CHANGES. This time last WEEK I was faced with 320 files to edit manually so the utility is a vast improvement on that situation. Sidewinder, I am perplexed that the way XP Home processes batch files is different to the way XP Pro does it. I guess we may never know why this is unless Bill Gates joins the forum! Regards, Les. |
|
| 6152. |
Solve : Removing all text after a certain line/character? |
|
Answer» Well, I'm trying to remove all the text after a certain character by using a batch file. For example, if I want to remove all text after the line end in the file test.txt, I've got a tiny bit of code, but I don't know what to do next. for /f "delims=: " %%i in ('findstr /n . "C:\test.txt"') do ( I would not use that to loop through a file line by line. OK I will slightly RELAX my rule and help you with your homework. If you are going to blindly copy code from wherever, copy good code! What is wrong with this?... Quote for /F "delims=" %%L in (C:\test.txt) do ( Quote Just wondering, how do I check how many lines there are in a file without knowing the contents? (I can check how many there are if I know what the last line/character is) use set /a to put a variable to zero. read through the file one line at a time, each time add 1 to the variable using set /a, when the loop finishes you know how many lines it has. Look, as much as you don't want to believe it, this is NOT homework! Also, I made this code myself, not copy it. With that out of the way, I am still looking for a way to remove text through batch. And the reason that I use findstr is to find out what line end (or whatever a am looking for) is on. Current Revision: Code: [Select]@echo off set /a LNE=0 set /a DOT=1 :find set /a LNE=%LNE%+1 for /f "skip=%LNE%" %%m in ('findstr /n . "C:\test.txt"') do ( cls if %DOT% EQU 1 echo Searching line amount. if %DOT% EQU 2 echo Searching line amount.. if %DOT% EQU 3 echo Searching line amount... if %DOT% LSS 3 set /a DOT=%DOT%+1 if %DOT% EQU 3 set /a DOT=1 goto find ) cls echo Running Program... echo. echo. set /a SKP=0 :begin if %SKP% GTR %LNE% goto end if %SKP% GTR 0 goto second :first for /f %%i in ('findstr /n . "C:\test.txt"') do ( echo %%i goto second ) :second set /a SKP=%SKP%+1 for /f "skip=%SKP%" %%i in ('findstr /n . "C:\test.txt"') do ( echo %%i goto begin ) :end echo. echo Done! echo. @pause ) :end echo. echo Done! echo. @pause Heh. I even added a little dot dot dot thing for fun. Anyway, I am still left with the original problem of how to delete text in a batch file. That is my only question.Quote from: Dark Blade on June 07, 2007, 02:44:31 AM Anyway, I am still left with the original problem of how to delete text in a batch file. That is my only question. You cannot directly modify a text file stored on disk easily. You have to make a copy which has the changes you want, then delete or rename the original, then rename or copy the new file back to the first filename. This is what in fact happens when you open a text file in an editor such as Notepad, make changes, and save the changed file, only it's all hidden from you, so that you only need the concept of "altering" just the one file. When you dig deeper, as you are doing, you need to appreciate such things. Quote from: Dark Blade on June 07, 2007, 02:44:31 AM Anyway, I am still left with the original problem of how to delete text in a batch file. That is my only question.a rough vbscript solution: Code: [Select]Const ForAppending=2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\temp\test1.txt", 1) Set objOutFile = objFSO.OpenTextFile("c:\temp\temp.txt", ForAppending,True) Do Until objFile.AtEndOfStream strNextLine = objFile.ReadLine If InStr(strNextLine,"end") = 1 Then objOutFile.Close objFile.Close objFSO.DeleteFile("C:\temp\test1.txt") objFSO.MoveFile "C:\temp\temp.txt" , "C:\temp\test1.txt" WScript.Quit Else objOutFile.WriteLine(strNextLine) End If Loop So, contrex, all in all, is it impossible (or close to) to make a batch file that, as you put it, does this: Before:- apples pears bananas end mangos lemons After:- apples pears bananas end You say that you have to make the changes manually to a copy of the file, and because of that I can't make a file that automatically deletes text. Well, anyway, THANKS for the help.I repeat, Quote You cannot directly modify a text file stored on disk easily. You'd need to be able to alter the disk sectors directly, and update the file size data etc. You have to make a copy which has the changes you want, then delete or rename the original, then rename or copy the new file back to the first filename. This is what in fact happens when you open a text file in an editor such as Notepad, make changes, and save the changed file, only it's all hidden from you, so that you only need the concept of "altering" just the one file. When you dig deeper, as you are doing, you need to appreciate such things in order to make any progress. Quote You say that you have to make the changes manually to a copy of the file, and because of that I can't make a file that automatically deletes text. I didn't say that at all. (Is English your first language?) I have said that you can write a batch file that appears to "alter" a text file, ie, before you run the file, there will be a file called fruits.txt that contains the following lines apples pears bananas end mangos lemons And after the batch file has finished, there will still be a file called fruits.txt but it will have a later file modified date than the first one, and a different size, and it will contain these lines apples pears bananas end Quote QuoteYou say that you have to make the changes manually to a copy of the file, and because of that I can't make a file that automatically deletes text. Well, sorry if I misinterpreted you. I thought that was what you meant when you said: Quote You have to make a copy which has the changes you want I didn't see your edit (I posted before it was written), so I didn't grasp everything you meant. Now I understand it.Quote from: Dark Blade on June 07, 2007, 03:25:00 AM so I didn't grasp everything you meant. Now I understand it. So now are you going to get coding and we can help you along? I may sound repeatative, but I don't know how to alter text into files. How do you do that? Is there any command that can alter/manipulate text? If I get that, then I'll start with some easy, like adding a 1 to the end of each file. Like this: Before:- apples pears ADD After:- apples pears ADD bananas I don't what exact code, just something to push me in the right direction (because making the code is half the fun!)Quote from: Dark Blade on June 07, 2007, 04:01:43 AM I may sound repeatative, but I don't know how to alter text into files. How do you do that?you can alter text in a number of ways 1) looping over the original file using for loop, changing whatever text then echoing the changed line out to another file 2) using available tools, like edlin, findstr , find, type, more , grep etc etc...plus using the >> , > redirection operators 3) using other languages that are more suited for text processing, eg perl/python/awk/sed/vbscript, even Java/powershell etc etc etc . They have more string functions than what DOS batch can offer you and you can have more control over what you are doing 4) others etc etc You can just completely rewrite that file with the batch file....Quote from: Carbon Dudeoxide on June 07, 2007, 05:15:28 AM You can just completely rewrite that file with the batch file....huh? don't understandif the file you wanted to edit was a batch file like this: Code: [Select]@echo off echo hello echo how are you echo. pauseand say you wanted to add a "echo i'm good", do this: Code: [Select]@echo off del "C:\path\file.bat" echo @echo off >>"C:\path\file.bat" echo echo hello >>"C:\path\file.bat" echo echo how are you >>"C:\path\file.bat" echo echo. >>"C:\path\file.bat" echo echo I'm good >>"C:\path\file.bat" echo pause >>"C:\path\file.bat" This would delete the old one and create a new file with the added sentence. The finished product would be: Code: [Select]@echo off echo hello echo how are you echo. echo I'm good pausewow fantastic! but what has this got to do with what OP wants?Quote from: ghostdog74 on June 07, 2007, 08:06:08 AM wow fantastic! but what has this got to do with what OP wants?well....he wanted to replace a line of text.... This is another way to 'replace' something Quote from: Carbon Dudeoxide on June 07, 2007, 08:08:43 AM Quote from: ghostdog74 on June 07, 2007, 08:06:08 AMwow and if the input file has 1000000000 lines, are you going to key in a batch file with 1000000000 echo lines ?The whole idea of text processing in batch files has now been explained exhaustively in about 6 different ways, and I would have thought that if a person had not "got" it by now, it would be time to find a less taxing hobby.wow fantastic! but what has this got to do with what OP wants?well....he wanted to replace a line of text.... Quote from: Dark Blade on June 07, 2007, 04:01:43 AM Is there any command that can alter/manipulate text? If I get that, then I'll start with some easy, like adding a 1 to the end of each file. Like this:Adding a line of text to the end of a file is easy. If your file is named food.txt, then your code would be: Code: [Select]echo bananas >>food.txtQuote from: GuruGary on June 07, 2007, 11:43:41 PM Code: [Select]echo bananas >>food.txtLOL funny. That code puts the text at the end of the file you want to edit.Finally... Adding - Can do Replacing whole file - Can do (so many echos... ) Deleting I just made something that deletes a file if it exists, then add lines to the new file (like what Carbon Dudeoxide did, but it adds the output of my batch file). I'm going to start making something that deletes all text after a specified line. |
|
| 6153. |
Solve : command file to execute at boot before win XP launches...? |
|
Answer» Hello, |
|
| 6154. |
Solve : close a *.bat file from another *.bat file? |
|
Answer» can i do that? and how?Use taskkill: TASKKILL [/S system [/U username [/P [password]]]] Reply if you want something more specific.if its not to much to ask, can it be a tad simpler, if it can't, thank you!Quote from: Amrykid on July 03, 2007, 09:23:53 PM can i do that? and how?show your code. Well, to simplify, I need your code, as ghostdog has just asked. But if you only hae one specif that you want to close, do this: taskkill /f /im filename.batStart=sys\VSCAN\scanner.bat @echo off ping -n 1 -w 1000 1.1.1.1 >nul echo 3 seconds to completion... echo. ping -n 2 -w 1000 1.1.1.1 >nul echo 2 seconds to completion... echo. ping -n 2 -w 1000 1.1.1.1 >nul echo 1 second to completion... echo. ping -n 2 -w 1000 1.1.1.1 >nul echo. echo Writing results... REM EXIT="sys\VSCAN\scanner.bat" ECHO Scan COMPLETED! pause echo Gathering scanned item data pause start=sys\VSCAN\results.txt exit "sys\VSCAN\scanner.bat _________________________________ thats the code i used for a project i was doing. the problem in the code is exit "sys\vscan\scanner.bat"Is that the contents of scanner.bat? And is that actual code? \/ Start=sys\VSCAN\scanner.bat If you want real code (you'll need to here), do the FOLLOWING: start "scanner.bat" "filepath\filename.bat" And for your exits, do this: taskkill /f /im "windowtitle eq scanner.bat" Tell me if you get all that, or to tell me if I'm wrong.Quote from: Amrykid on July 03, 2007, 11:38:43 PM Start=sys\VSCAN\scanner.batI say you indeed have a design problem. Do everything in your scanner.bat BATCH file. you don't need a separate batch ...otherwise, show your scanner.bat file.i found out the problem. its was that i forgot to put exit in the choice area. Yall remined me of that. thanks! |
|
| 6155. |
Solve : Error Check? |
|
Answer» Hi Guys, |
|
| 6156. |
Solve : Creating Log file? |
|
Answer» Anybody can help plz to find the way to CREATE a log file while I am runnning a batch file, ie all the steps performed and messages shown by RUNNING the batch file to be COPIED in a logfile. |
|
| 6157. |
Solve : Changing CMD.EXE prompt and current working directory permanently? |
|
Answer» Hello, The standard prompt shows the current logged directory (the directory you are in). if you want to see "C:\" at the prompt, why not just type Or... just CD\ would do the same thing but then the OP would have to type his Prompt command each time or maybe set up a .bat file to create the required Prompt.. Creating the Shortcut to the Command Prompt as explained in my first response above does the lot with just ONE click and there are also other options available such as using a Window or Full Screen mode that the OP might get round to investigating.. Neither CD C:\ nor CD\ clears the version information which the Op describes as "Windows version crap", he'll have to type CLS as well!! The shortcut to Command Prompt will open either a clean Command Prompt Window or Full Screen as selected by the OP. Problem solved. Thanks a lot. I just used $_ to clean up the command prompt, but I can experiment a little more to figure out what I want.How will you know what directory you are in? Are you never, ever, going to be in another directory? I tried prompt $_ and got just a blinking cursor and a two line gap between commands. A nightmare! I just used $_ to feed the information that I had to a new line. I didn't want the information all on one line so I had to move it down. I added $P$G to the end of the "target" for the shortcut to put my current working directory as C:\> which is the current path. I'm pretty sure you know all of this, but here's where I have it now Target: C:\WINDOWS\system32\cmd.exe /K PROMPT Welcome Jacob Howarth!$_$V$_$T $D$_$_$P$G Start in: C:\ This under the shortcut tab that Dusty mentioned above. However, I have another problem, I was wondering if I could get it to not print the same prompt EVERYTIME I enter a command. For example my current cmd.exe window shows this Welcome Jacob Howath! Microsoft Windows XP Version [5.1.2600] 19:24:00.46 Tue 07/03/2007 C:\ However, whenever I type a command "cd" or something it prints the same information after each command is entered. I only want it to display at start up. Does anyone have any guidance? I would gladly appreciate it.If you just want a neat opening message, you might be better off leaving the prompt alone and making the shortcut target something like this C:\WINDOWS\system32\cmd.exe /K echo Welcome Jacob Howath! & ver & echo %time% %date% Unfortunately I cannot get %date% to show the 3 letter day of the WEEK ("Wed"), I think this depends on your locale, in my locale, English (United Kingdom) I just get dd/mm/yyyy eg 04/07/2007 but I believe in the English (US) locale you would get "Wed 07/04/2007" Thanks for the advice. It works perfectly. |
|
| 6158. |
Solve : Unable to delete hidden file? |
|
Answer» I have a hp machine with MS ME os. I acquired this some time ago and use it as a means to print photos. I recently found that it has been making daily backups to a directory named _restore which has the attrib of hidden. It has over 3 gigs of info in it and has the free space down to 1 gig. |
|
| 6159. |
Solve : Write < and > to a file with batch? |
|
Answer» Hi there >>test.xml echo this will appear in file ^<TEST1^>This is a test^</test1^> This solved my problem. Thank you so much for your quick help, contrex Cheers and greets You're welcome. When I wrote "... if you want them to show up in files" of COURSE I should have added "or on the screen"I have another question, if u don't mind I'd like to somehting like this Code: [Select]@echo off set towrite=test (this is just a simple example, in my batch it reads from a file etc and then the batch sets towrite=test) >>test.xml ^<%towrite%^> pause So, I'd like to write my towrite between the < > tags, how do I do that? Code: [Select]@echo off set test=test >>test.xml ^<^%test^%^> pause The above code doesn't workYour code @echo off set test=test >>test.xml ^<^%test^%^> pause 1. You have set the environment variable named test to hold the string "test". 2. A SIDE issue - it can lead to bad confusion if you call variables the same as their contents. 3. You missed out "echo" in your third line which should look like this I guess >>test.xml echo ^<^%test^%^> 4. However this will result in nothing being written to test.xml since you have escaped the % signs surrounding the variable name. 5. If you remove the carets in front of the % signs >>test.xml echo ^<%test%^> test.xml holds this line <test> 6. If you escape the % signs you no longer have a variable. |
|
| 6160. |
Solve : Batch Files executing at shutdown? |
|
Answer» I am looking to execute a batch file that I have created, but I do need it to execute in a special way: I am looking to execute a batch file that I have created, What he needs is for you to tell him how to get his batch file to run at the time he needs it run: Quote but I do need it to execute in a special way:This is strange. I presume "clocked out" means "logged out". When somebody with sufficient privileges initiates a shutdown, all users are logged out automatically. However, to run a script or batch at shutdown. select Start | Run and type gpedit.msc, then click OK; then look in Computer | Configuration | Windows Settings | Scripts (Startup/Shutdown). Double click Shutdown in the right-hand pane, then click Add to add one or more scripts as needed. Is it me, or will the code posted previously not WORK because choice was replaced in Win XP. That is if he's running Win XP.Quote from: Jake1234 on July 04, 2007, 01:31:19 PM Is it me, or will the code posted previously not work because choice as in choice.com ? Quote was replaced in Win XP. That is if he's running Win XP. choice.com is not being used in the batch FILES above. Side note, just in case anyone is USING Search and stumbles across this thread: If you need a copy of choice , here is one place to visit. >Click here< Quote from: Jake1234 on July 04, 2007, 01:31:19 PM Is it me, or will the code posted previously not work because choice was replaced in Win XP. That is if he's running Win XP. a variable called "choice" is being used, but neither choice.com nor choice.exe is being called. |
|
| 6161. |
Solve : Bat PROBLEM!!!? |
|
Answer» i made a batch file that can make other batch real easy. since today, i made some changes to it. |
|
| 6162. |
Solve : my question is this....................pls let me know? |
|
Answer» Dear All Expert, |
|
| 6163. |
Solve : Type using Dos? |
|
Answer» can u like make ur computer TYPE some thing using a comand PROMPT? |
|
| 6164. |
Solve : RAMDRIVE AND WINDOWS XP? |
|
Answer» HELLO, I would like to know if there is a way to set a ramdrive under windows xp using command line in a batch file. If yes is it possible to setup DOS 6.22 on it and use it under windows XP? could you please help me posting examples? thank you very much.You cannot boot a DOS disk from inside Windows XP whether the disk is a RAM disk or another kind. maybe you are THINKING of VMWare? no it was just the point of creating a ramdrive while under winxp with a batch file like INSTANT ram drive perhaps using Qemu?You need to load a ramdisk driver at start up. See here http://support.microsoft.com/kb/257405/en-us |
|
| 6165. |
Solve : how to Get PID.....!!? |
|
Answer» how can we get PID of running batch file.....? can anyone help me on this topic...? pls it's very urgent.......!! help me......!!in batch, you can use tasklist to display your batch file's PID. eg Code: [Select]tasklist /FI "IMAGENAME eq yourbatch.bat " /NH you will then need a for loop to parse out the correct fields... aren't "urgent" batch questions usually homework?maybe he did write a sysadmin batch and tried running it, but it hangs, so he needs to find PID to kill it? for whatever reasons he needs to do that, let's just give him the benefit of the doubt. btw, just curious, does schools nowadays teach DOS batching?Quote btw, just curious, does schools nowadays teach DOS batching? They certainly do. Quite a lot teach QBasic as well. They are included in the OS, no extra licences to buy, and they do enable the learning of many programming concepts. Quote from: contrex on July 04, 2007, 02:45:37 AM Quotethanks. I usually thought most schools would start with C/C++ for teaching programming concepts, SINCE its very close to the interaction with the OS, ie memory manipulation etc..DOS/QBASIC does not teach programming concepts, IMO.Quote from: ghostdog74 on July 04, 2007, 03:14:12 AMbtw, just curious, does schools nowadays teach DOS batching? [DOS/QBASIC does not teach programming concepts, IMO. That's rather snooty. Perhaps you would care to elaborate, although we would be getting a liitle OT I guess. I wrote "many" programming concepts. (not all, by any means) Learning to program in ***any*** language, assembler, FORTH, SMALLTALK, C, Python, APL, BCPL, batch, is going to give the student some experience in dealing with fundamental concepts of programming. I started with BASIC in the 1980s and it certainly was a good foundation when I later went on to use Pascal, C and Fortran. I have taught classes of students using QBasic, and many of the more apt students went on to study computer science at a higher level. Quote Computer Programming-Basic I http://www.flvs.net/students_parents/VSACourseDetail.php?CourseID=43 Dartmouth BASIC was DEVELOPED in the 1960s to ***introduce*** students to programming concepts. Of course, QBasic is more or less a "toy" language compared to more advanced languages such as C, C++ etc, but (I hope you will forgive me for saying this) I am afraid your comment reveals more about your pride and vanity than it does about your knowledge. Quote from: contrex on July 04, 2007, 03:26:07 AM That's rather snooty. Perhaps you would care to elaborate, although we would be getting a liitle OT I guess.my little "IMO" thing sure INCURRED your "wrath" didn't it. You may be right, DOS/QBASIC does provide you basic concepts, but that's just it. Programming concepts entails alot more of other stuffs, such as OO, bits/bytes manipulation, data types eg int,float, longs, interfacing with the OS/hardware, complex maths , memory management/manipulations, algorithms, spaghetti codes, etc you name it. DOS/QBASIC just doesn't make it in some of these areas. Like I already said, its just IMO. So no need to get agitated. Before getting real OT, i will stop here. i'v run 2 java file so that TASKLIST option is showing two image Name (java.exe) and different PID (like as 2460 & 3789) now suppose if i want to do stop one (java.exe) whose PID is 2460. then how could i recognized that i'v closed java.exe file of a particulare PID (2460)......? pls let me know help me Best Regards AshutoshQuote from: toshashu123 on July 04, 2007, 04:17:49 AM i'v run 2 java file so that TASKLIST option is showing two image Name (java.exe) and different PID (like as 2460 & 3789) now suppose if i want to do stop one (java.exe) whose PID is 2460. then how could i recognized that i'v closed java.exe file of a particulare PID (2460)......? Run tasklist again, and check that PID 2460 is gone if the java.exe running and u type TASKLIST again and again then it shows same PID for that particular image name it doesnt change. It does only change in case of another java.exe file is runDear All Members, i'm running batch file(start.bat) which run my java aaplication and this batch file stored at C:\ABC\XYZ\start.bat with PID like as 1792 and another batch file with same name run from this location C:\CMD\MNC\start.bat with PID like as 8967 and another batch file with same name run from this location C:\JKL\GHI\start.bat with PID like as 4356 now i make another batch file (kill.bat) and stored at each location. Now i run kill.bat from ( C:\CMD\MNC\kill.bat ) this location. my question is this that how could i found the PID of start.bat which is run from this location (C:\CMD\MNC\start.bat) and kill this process by KILL.bat file.....? If anybody help me. please revert back to me. I'v been tried two file that is KILL_FIRST.bat and KILL_LAST.bat but didnot get success. KILL_FIRST.bat @echo off REM **** KILL_FIRST.BAT **** set TASKNAME=java.exe SETLOCAL ENABLEDELAYEDEXPANSION echo Task list before KILL... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo [Task %TASKTOTAL% is last] echo IF START if %TASKTOTAL%==0 goto :eof set TASKCOUNT=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKCOUNT=!TASKCOUNT!+1 if !TASKCOUNT!==1 taskkill.exe /F /PID %%B ) echo Task list after KILL... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo LOOP-3 END echo [Task %TASKTOTAL% is last] KILL_LAST.bat @echo off REM **** KILL_LAST.BAT **** set TASKNAME=java.EXE SETLOCAL ENABLEDELAYEDEXPANSION echo Task list before KILL_LAST... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo [Task %TASKTOTAL% is last] if %TASKTOTAL%==0 goto :eof set TASKCOUNT=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKCOUNT=!TASKCOUNT!+1 if !TASKCOUNT!==!TASKTOTAL! taskkill.exe /F /PID %%B ) echo Task list after KILL_LAST... set TASKTOTAL=0 for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "imagename eq %TASKNAME%"') do ( set /A TASKTOTAL=!TASKTOTAL!+1 echo [Task !TASKTOTAL! is "%%A %%B"] ) echo [Task %TASKTOTAL% is last] Can anyone help me on this topic pls..........? Best Regards AshutoshOK, this is the third place you've asked that question. Stop now.This might be a waste of time, but if it rids us of the nuisance it will be worth while... Quote my question is this that how could i found the PID of start.bat which is run from this location (C:\CMD\MNC\start.bat) and kill this process by KILL.bat file.....? Here are DETAILED INSTRUCTIONS. Use the knowledge gained to write batch file or perform task from command line. 1. Plant an unique identifier into each start.bat. Add a line to each start.bat such as title "identifier999" (or some other title meaningful to you) 2. Now you can filter Tasklist output by window title 3. Use /v switch to get verbose output which includes window titles. 4. Use /NH switch to hide header lines. 5. Use /FI switch to apply filter "WINDOWTITLE eq indentifier999" 6. It is now a trivial task to extract the PID (it is the second token using space as delimiter) 7. Now use taskkill /PID NNNN to remove the task. Example... c:\>tasklist /v /NH /FI "WINDOWTITLE eq identifier999" cmd.exe 3916 Console 0 2,396 K Running PUPP-C92F25ED23\Mike 0:00:00 identifier999 Here PID is 3916 start1.bat @echo off title START_ONE pause start2.bat @echo off title START_TWO pause kill_start1.bat for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "windowtitle eq START_ONE"') do taskkill.exe /PID %%B kill_start2.bat for /F "tokens=1-2" %%A in ('tasklist.exe /nh /fi "windowtitle eq START_TWO"') do taskkill.exe /PID %%B |
|
| 6166. |
Solve : Help setting a variable in a Batch that is copied to a text file? |
|
Answer» Hello, Hello, 1.) Can you show us some of your code, so we can get a feel for what you are trying to do? 2.) In the meantime, what happens if you do something like this in your batch file? : ECHO %variable_name_here% > filename.txt or echo %variable_name_here% >> filename.txt Is this a homework assignment? And what operating system are you using?Not A homework assignment I just would like some help. Let give more details. Hardware and operating system: AMD Opteron 848 server running Windows Server 2003 SP1. I need to set a variable in the batch so the users can change them in one place each month. The essmsh COMMAND starts the Essbase interface in interactive mode. The variables I'm trying to set need to update in CopySPS.txt prior to the essmsh line running. In CopySPS.txt they are set again so that Essbase can save them as user defined variables which are then used in calculation scripts. ***************BATCH SCRIPT************************************** Set clearscen = Actual\\Forecast_2007 Set ClearStart = May essmsh E:\Hyperion\HypData\EssAdmin\SPS\CopySPS.txt ***************************************************************** ***************************COpySPS.txt****************************** /* pdate the specified variable VALUE. !!(SV_OptA_1, SV_OptA_2, SV_OptA_3, No Change)!!*/ alter database GL.GL set variable "clearscen" "Actual\\Forecast_2007"; alter database GL.GL set variable "clearstart" "May"; ******************************************************************** So you want to be able to save CLEARSCEN and SLEARSTART to a file and be able to change them in the batch file? You can save them to a file like: Code: [Select]Set clearscen=Actual\\Forecast_2007 Set ClearStart=May echo %clearscen% > E:\clearscen echo %ClearStart% > E:\ClearStart You read them in like: Code: [Select]set /p clearscen=<E:\clearscen set /p ClearStart=<E:\ClearStart echo clearscen=%clearscen% echo ClearStart=%ClearStart% Obviously, you don't want the static SET in your batch file if you are reading the variables from a file, you just need something to set them with the first time. Is that what you were looking for? Hey GuruGary, Correct I need to be able to set and change variable in the batch script and have variable change in the text file. The text file actually contains the instructions that Essbase will use. So in sequence of events it should be the following. 1 Set variable in batch and save batch 2 Kick of batch 3 Batch sends variable to a specific place in the text file 4 Batch calls text file using essmsh command which reads text file with Essbase command containing changed statement. 5 Essbase executes instructions in text file ThanksQuote from: lostdude on May 11, 2007, 12:10:09 PM 1 Set variable in batch and save batchSet what variable, and where do you get the information on what the variable is, and what the value is? And what do you mean "save batch"? The batch file should be static. Please explain. |
|
| 6167. |
Solve : How can i Enable or Disable my Lan Card vise versa in using DOS commands?? |
|
Answer» How can i Enable or Disable my Lan Card vise versa in using DOS commands? |
|
| 6168. |
Solve : Logging user/computer information with batch file? |
|
Answer» I've created a script that will perform a certain action, but I need to know who is using the script. Is there a way to log PC and USER information in a log using a batch FILE? Also, is there a way to make this silent? Please let me know! I've seen some things that can be used like 'net session' or whoami (available in RESOURCE kit - and 'nix flavors), but where ever I look, i can't find a way to log this information. Any help would be greately appreciate! Thanks in advance! Jeremy I forgot to mention that I'm running in Windows XP environment. |
|
| 6169. |
Solve : Make batch files run invisible? |
|
Answer» how do you make a batch file that after it opens it will carry out the commands invisibly? I can see this sort of informating getting into the wrong hands...Same...this information can be used for.....odd purposes...Thank you |
|
| 6170. |
Solve : batch file as backup: delete oldest file(s)?? |
|
Answer» Hi, and thanks in advance for reading. |
|
| 6171. |
Solve : How to wait in a batch file for ending of some event?? |
|
Answer» So I write a batch file, which has a task to stop a Tomcat server and to start it again. |
|
| 6172. |
Solve : Help a poor noob please? |
|
Answer» I would like to know if it is possible using cmd to open a MESSAGE only if ANOTHER program is RUNNING |
|
| 6173. |
Solve : FOR command help needed? |
|
Answer» Hi there Problem 2: to see if any particular file is in use by another program, you can use handle.exe, part of the XP Reskit, free from Microsoft at http://www.microsoft.com/technet/sysinternals/SystemInformation/Handle.mspx Download it and put in somewhere on your PATH eg to see if afilename.zzz is in use handle | findstr /i "afilename.zzz"> nul && echo is in use So you could do this :wait handle | findstr /i "%XML%\%%A\%%~A.xml" && goto wait %AltovaXML% /VALIDATE %XML%\%%A\%%~A.xml A lot depends if MapForce creates the xml file STRAIGHT away, and releases it when it has finished, or if it just writes it out at the end of its processing... |
|
| 6174. |
Solve : Run two programs under DOS? |
|
Answer» How to run two program at the same time under dos. |
|
| 6175. |
Solve : If no Data Found in Drive Rename a Certain Folder with a Time-Stamp-Date? |
|
Answer» Is there a way in "XP's DOS-CMD-BATCH" to check a specific removable storage drive for data in it, and if it doesn't find anything or detect the drive as being active have it then proceed to RENAME a specified folder with a time-stamp-date... |
|
| 6176. |
Solve : Batch file help.. rename file Windows 2003 Server? |
|
Answer» Hello Group! |
|
| 6177. |
Solve : Opening specific webpage?? |
|
Answer» Well, I've tried out the LINK that CBMatt PUT up, and it OPENS the email, but is there anyway for it to send (and furthurmore, to attach files)?My favorite tool for SENDING email over command LINE is Blat |
|
| 6178. |
Solve : Prevent to delete file.? |
|
Answer» Hi Everybody!! |
|
| 6179. |
Solve : delete index.dat? |
|
Answer» Hi Everybody!! You can use the del command. No, It's not work for index.dat Thanks, JayWhat about with the /f switch? Code: [Select]del "C:\path\to\file\index.dat" /fIf we will try to delete this one, we always get MESSAGE bcz its all time get accessing by window/Explorer. The process cannot ACCESS the file because it is being used by another process. RD even not work if it in folder. Thanks, Jaywhere is this file? It could be a core file for a program.Without using third party software, how about making a batch file with the code Code: [Select]del C:\Documents and Settings\%username%\Cookies\index.dat del C:\Documents and Settings\%username%\Local Settings\History\History.IE5\index.dat del C:\Documents and Settings\%username%\Local Settings\History\History.IE5\MSHistXXXXXXXXXXX\index.dat del C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\Content.IE5\index.dat del C:\Documents and Settings\%username%\UserData\index.datand make this batch file run on startup? This will work for WINDOWS 2000 and XP, I'm fairly sure that's all the locations of index.dat files. If I missed any, add them in. Edit: Carbon, index.dat is your history. It is always in use by Windows Explorer and other programs. It can only be deleted on startup.Quote from: Carbon Dudeoxide on May 07, 2007, 03:33:25 AM where is this file? It could be a core file for a program. C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files\Content.IE5 \index.dat Quote from: Calum on May 07, 2007, 03:36:23 AM
It's not work with start up . Not deleted. Unable to delete even in safe mode.I wasn't sure if it'd work, that was the best I could do. Why not just use something like CCleaner?A batch file can delete index.dat on startup, but it will always be recreated by windows. You have to check the content of the file to see if it was actually deleted. In most instances, a newly created file will be 32K. Anything larger probably has content. It can be opened in Notepad, which is a rather crude display, but is adequate to view the contents to see if anything is actually there. You cannot totally eliminate index.dat.Quote from: 2k_dummy on May 07, 2007, 06:07:26 AM A batch file can delete index.dat on startup, but it will always be recreated by windows. You have to check the content of the file to see if it was actually deleted. In most instances, a newly created file will be 32K. Anything larger probably has content. It can be opened in Notepad, which is a rather crude display, but is adequate to view the contents to see if anything is actually there. You cannot totally eliminate index.dat.I did try, size is same after trying to delete through startup.It is a system file that cannot be deleted as referred to by 2KD.... What is it you are trying to accomplish ? ?Hi, There is a way to delete this file by creating new user profile, I am wondering if any way from dos. Like this file, could i set properties so it can't be deleted. Thanks, JayQuote from: patio on May 07, 2007, 03:31:58 PM It is a system file that cannot be deleted as referred to by 2KD.... |
|
| 6180. |
Solve : Run a .bat from VBA? |
|
Answer» Hi there, |
|
| 6181. |
Solve : IF command help...? |
|
Answer» Quote from: contrex on May 09, 2007, 10:28:25 AM I mean, I agree that his post was titled "IF command help...", but when you read the actual question, he wanted to know how to use the CHOICE command. The ORIGINAL poster asked for some help - of that we are sure. You are reading into it. I'm just reading what was written. I don't know what was in his head, nor do I know his level of expertise. He may have meant one thing, and said another.... it happens. No big deal. Either way, it really doesn't matter to the original poster. What MATTERS is that he got some useful help. Then you made comments that were not on TARGET, so I replied. There is no POINT in going on about it. |
|
| 6182. |
Solve : Doubt in Run As command? |
|
Answer» Hi all, |
|
| 6183. |
Solve : Command Prompt? |
|
Answer» I am new to command prompt but the F.A.Q.'s do not seem to answer my question CD = Change disk No, CD = change directory to change disk, just type the drive letter and a colon eg D: C:\Documents and Settings\Danny Gurganus Jr> is the prompt. You don't type it. Methinks you should study some more. About Change directory your wright but the path were the prompt start in is changeable I use this myself sow... I do agree that I don't know much about PC but the things I do know are true. accept for the misunderstanding of Directory and disk but that doesn't make any difference when you work white it. If your current directory isn't important to you, then you can just change your prompt. At your "C:\Documents and Settings\Danny Gurganus Jr>" prompt, type the follwoing: Code: [Select]set prompt=$n:... so your screen will look like: Code: [Select]C:\Documents and Settings\Danny Gurganus Jr>set prompt=$n:That will give you a prompt of just the drive letter (like you asked in your original post). |
|
| 6184. |
Solve : Run a Dos program in XP? |
|
Answer» I need to run an old Dos CAD program in XP |
|
| 6185. |
Solve : Need help to automatically create folders based on existing folder names? |
|
Answer» Hi there. |
|
| 6186. |
Solve : Trying to create zip file for a location that is provided by a user.? |
|
Answer» Hello. |
|
| 6187. |
Solve : Open a program @ night? |
|
Answer» Hi there, @echo off Try changing the highlighted line to: cd /d C:\Program Files\BitTorrent Changed still don't work If I go to scheduled task when the task should run I see under the status tab: the program could not be opened, however I'm 100% it existsWhat about QUOTES around the program path & name cd "C:\Program Files\BitTorrent" |
|
| 6188. |
Solve : run program.? |
|
Answer» Hi everybody!! |
|
| 6189. |
Solve : stopping loops? |
|
Answer» does anyone know how to stop a goto LOOP, @echo off Here is an example of the /a switch. It calculates '5+2' and echo's the answer. |
|
| 6190. |
Solve : Making multiple directories from a wordlist .txt file?? |
|
Answer» Is it possible to make multiple DIRECTORIES for each word from an alphabetical list stored in a txt file? |
|
| 6191. |
Solve : drive c has no label volume serial number 1d36-11eb....HELP!!!!? |
|
Answer» when i turn pc on it GOES to DOS screen and says:drive c has no label volume serial number 1d36-11eb. I dont KNOW how to remedy this. Any help is greatly appreciated.No remedy neccessarily needed...most drives operate fine without a volume label. when i turn pc on it goes to DOS screen and says:drive c has no label volume serial number 1d36-11eb. I dont know how to remedy this. Any help is greatly appreciated. Try this: 'c:' or what ever volume you know is there. then try running 'win'. Example: 'c:' 'win' or 'd:' and then 'windows'(if you have your installation on d:) if your volume doesnt have a name, it's no deal, but if it's got no drive letter, it can get worse. try renaming the volume(if that doesnt change anything on or with the partition) if this doesnt work, you might wanna check if a volume containing windows is installed in your system at all Problem solved elsewhere. Poster made duplicate posts in DOS and Windows sections. Poster omitted to state that computer is a freshly acquired used computer. DEALER or previous owner has removed Windows, as is the normal correct legal procedure. AHAAA ! ! Thanx.It is nice to have all of the relevant information up front. |
|
| 6192. |
Solve : MS-DOS V3.3 or less? |
|
Answer» Dear FRIENDS, Dear friends, Check out: http://oldfiles.org.uk/powerload/bootdisk.htm Is it there? |
|
| 6193. |
Solve : save output from cmd.exe? |
|
Answer» Microsoft Windows XP [Version 5.1.2600] If you don't want to replace the orignal file, but just add the text to it, use >> instead of > (but this only works if the file exists). On my system >> works whether or not the file exists beforehand. Quote from: insertusername on May 05, 2007, 02:01:14 AM yes. its work ,tq I just used output.txt as an example. You can type anything you like as a filename. |
|
| 6194. |
Solve : small batch program's I find and make enjoy from DeltaSpider? |
|
Answer» I GUESS I will keep it as is with XCOPY. From what I understood a regular copy does not allow the copying of SUBFOLDER especialy if they are empty. I do need to structure a way in which I can have the files backed up on Tuesday go to a folder called Tuesday and so on. What would be the best lay out for this?Depending on your regional settings, you can use the value of the date command: |
|
| 6195. |
Solve : running programs at start-up? |
|
Answer» I know how to run programs at start up using Command Prompt, but is it possible to make a program that asks the USER if they want to OPEN that program?If you have Win 95/98/ME you have choice.exe ALREADY. If not, download it from one of a zillion places and put it on your PATH somewhere. If you have Win 95/98/ME you have choice.exe already. If not, download it from one of a zillion places and put it on your PATH somewhere. And here: http://hp.vector.co.jp/authors/VA007219/dkclonesup/choice.html Thanks, it worked. |
|
| 6196. |
Solve : Printing a document using a batch file? |
|
Answer» I need help!!! How can I create a batch file that opens up a document in excel and prints the document to specific printer? Batch code does not generally do Windows. Using the print command on a Excel workbook/worksheet will produce gruesome results. |
|
| 6197. |
Solve : Running old dos datebase under windows? |
|
Answer» Hi |
|
| 6198. |
Solve : Hi. Need help processing files in a folder/directory? |
|
Answer» If I try to use for %%f in (*.txt) do(...), it doesnt seems to process all the text files in the folder, rather it repeats the same file to do the processing. |
|
| 6199. |
Solve : Delete a folder under several users profiles.? |
|
Answer» Hey all. |
|
| 6200. |
Solve : batch to compare and rename same file? |
|
Answer» Hi, |
|