Explore topic-wise InterviewSolutions in .

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.

5151.

Solve : displaying file inside the directory ???

Answer»

Hello everyone ,

how can display the FILE inside the directory can you help me please i used dir command but it displays garbage Filter:

Code: [Select]dir /s <file to SEARCH for>Quote from: emuhulk on September 11, 2009, 05:36:52 PM

where can i put directory inside the dir command

dir /s "directory"
dir /w "directory"
dir /b "directory"
dir /s /b "directory"

take your pick.

directory can have wild cards e.g. "directory\*.txt"



Quote from: emuhulk on September 12, 2009, 06:57:16 AM
thank you it is working

but i have one more question how can i capture this name of file in that directory and echo to USER like run test.bat without extension of file .bat

for example

echo do you WANT run test settings

thank u


Code: [Select]for /f "delims==" %%A in ( ' dir /b directory\*.bat ' ) do (
echo Do you want to run %%~nA settings
)

5152.

Solve : Set Var=??

Answer»

Thank you thank you thank you.

Yes that will work perfectly. Thank you for all your help. Thought of something. After running the BAT file I want to rename or delete the bat file so it can't be run again. I know I could set a variable using the %CD%, but I noticed that is the bat file is run from the command as follows ...

Code: [SELECT]c:
cd program files\bat
"folder\edit.bat"

If I set local=%CD% in the bat file that is run, I will get 'C:\Program Files\bat' as my local variable. Is there a way around this to force it to take the actual location of the bat file so I can remove it? QUOTE from: nothlit on May 15, 2008, 09:55:11 AM

Is there a way around this to force it to take the actual location of the bat file so I can remove it?

the filename + extension of a batch file is contained in the variable %0 (percent zero). The full name would be

%~dpnx0

so, adding quotes in case the path and/or name has spaces,

del "%~dpnx0"

would make a batch delete itself, but you would get an error message because you have deleted the running batch from within itself.


Ok, so %0 gives me the whole path, but what is the ~dpnx REFER to? or is that like sending commands to the delete command? Ok, I think I found something. I did Call /? in a command prompt and find %~dp1 - expands %1 to a drive letter and path only, but still confused on the nxThey are standard variable modifiers.

If you typed for /? at the command prompt, didn't you see this?

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a FULLY qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file

they can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only

so if %0 is a batch file's own name and extension, then

%~d0 is its drive letter with a colon
%~p0 is the full path to its folder
%~n0 is its bare name without extension
%~x0 is its extension with a dot before in front of it (usually .bat or .CMD)

Put them together adding quotes in case the path has spaces and you get:

"%~dpnx0"


Thank you for the explanation.
5153.

Solve : what is wildcard character ? is * or ' '?

Answer»

Hello everyone ,

can you show example about wildcard character please

thank you Dir /b /s *.Txt

That will list all the txt files in a FOLDER and all it's subfolders. The asterisk (*) REPRESENTS any string of zero, one, or more characters while the QUESTION MARK (?) represents any ONE character.Here you go - here's a good page for you: http://ieeexplore.ieee.org/xplorehelp/Help_Searching_with_Wildcard_Characters.html

5154.

Solve : Formatting FOR Loop Value?

Answer»

Hi All,

Am curious to know how I'd format the %%i value to display two digits. (01, 02, 03, ..., 09)
I currently have ...Code: [Select]for /l %%i in (1,1,%MonitorLoops%) do (
if %%i LEQ 9 (set %%i=0%%i)
echo Check %%i - Performed at %TIME%
)And not surprisingly, not getting the result I was looking for.
Can ANYONE part with suggestion on how I'd answer this formatting query ??

Cheers,
CameronI'm sure this could be done in a very clever way, but down and dirty also works:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,%MonitorLoops%) do (
set num=%%i
if %%i LEQ 9 set num=0%%i
echo Check !num! - Performed at %TIME%
)

How's the project coming Cameron?

How about this...

using set /a avoids a string comparison

Code: [Select]@echo off
setlocal enabledelayedexpansion
set Monitorloops=20
for /l %%i in (1,1,%MonitorLoops%) do (
set /a num=%%i
set pad=
if !num! LEQ 9 set pad=0
set num=!pad!!num!
echo Check !num! - Performed at %TIME%
)

Or do the padding in a loop

Code: [Select]@echo off
setlocal enabledelayedexpansion
set Monitorloops=20
REM 1=no padding, 2 upwards=pad with zeros
set digits=2
for /l %%i in (1,1,%MonitorLoops%) do (
set /a num=%%i
set max=&set pad=
for /l %%p in (2,1,%digits%) do set max=9!max!&if !num! LEQ !max! set pad=0!pad!
set num=!pad!!num!
echo Check !num! - Performed at %TIME%
)
Many thanks SIDEWINDER & Dias ,

Took a snippet from each of your offerings to keep it short & sweet ...Code: [Select]for /l %%i in (1,1,%MonitorLoops%) do (
set /a num=%%i
if !num! LEQ 9 set num=0!num!
@echo Check !num! - Performed at %TIME% >> %OutputLog%
Quote from: Sidewinder on JUNE 03, 2008, 11:32:23 AM

How's the project coming Cameron?
All done (well kinda).

Have finished preliminary testing and all is working as it should. The task is an sftp monitor and transport script using Bitvise's sftpc.exe application.

Intent is that files come to a sftp server (where this script is located) from a HP-UX box. This script will monitor for the existance of a trigger file and when found, attempts to CONNECT and push the received 'data' file (received prior the trigger) to a remote sftp service. This is to maintain PCI complience - Both the HP-UX server & Remote SFTP server have Security POLICY & Practises that neither allow direct transfer (push & pull) of data .. and the same type of direct transfers are not permitted under PCI.

I've just to code the clean up after each transfer (won't take long).

And then to wait on the guys in Europe to get their end ready for some end-to-end testing.

Cheers,
Cameron
5155.

Solve : I need help with the "IF" command?

Answer»

Ok well today I tried using two variables inside the "IF" command and checking to SEE if one variable is larger then the other, it of course is rigged for one variable, yet I continue to have it say that the smaller numbered variable is higher and continueing as if it never did the math it just went with the "goto" code at the end of the which ever "if" statement was first.
So here's the code if what I typed doesn't make sense.
Code: [Select]@echo off
set Test=6
set Test2=12
if %Test% GTR %Test2% goto :Done
if %Test2% GTR %Test% goto :Done2
:Done
It failed.
pause
:Done2
It worked.
pauseEven though its rigged for "Test2" it will still goto ":Done" instead of going to where it should go which is ":Done2".
Any one have an idea as to why. Help is greatly appreciated.It WORKS for me....

I cleared it up a bit. See if it works or not.

Code: [Select]@echo off
set test1=12
set test2=6
if %test1% GTR %test2% goto :Done1
if %test1% LSS %test2% goto :Done2
:done1
echo. GTR
pause
exit
:Done2
echo LSS
pause
exitThanks I see where it was having problems. Never really thought to do it that way. Works like a charm now. THANKS again!any ideas what was wrong with yours?It seems it wasn't liking the...
Code: [Select]if %Test% GTR %Test2% goto :Done
if %Test2% GTR %Test% goto :Done2For what ever reason it wasn't liking the two "IF" commands that where both seeing if one was greater then the other. So I'm guessing that was the problem.I would think for that you would need:
Code: [Select]if %test% GTR %test2% (
goto :Done
) else (
goto :Done2
)

wait maybe not Hmm, maybe I'm not 100% sure if that was the cause. Also I don't ever use the "else" statement. It never likes me enough to work right , so I just work around it. Any way thanks for all the help! Have a good day/evening/night/morning(DEPENDING on your time zone).Anytime. Have a good day/evening/night/morning too. Darkenedheart, your first code worked fine on my system. I think when you ran it you must have typed something different from what you posted.

5156.

Solve : Certutil?

Answer»

Hello all,

I was hoping I COULD get a little help with the certutil.exe PROGRAM. I'm trying to import a pfx but keep getting an error with certuitl. Unfortuantly I can't find a whole lot of online resouces about this program so here I am =)

Here is the "current" command I'm trying

certutil -f -addstore "Intermediate Certification Authorities" C:\DevCert.pfx

This RESULTS in the error:
CertUtil: -addstore command FAILED: 0x80093102 (ASN: 258)
CertUtil: ASN1 unexpected end of data.

I've tried the -ImportCert as well but it ends w/ basically the same error. I import the cert through the wizard w/ no problemJust a thought, these command line programs often have built-in help, have you tried

certutil -?
or
certutil -h

just done a google and technet has these help pages
http://technet2.microsoft.com/windowsserver/en/library/a3d5dbb9-1bf6-42da-a13b-2b220b11b6fe1033.mspx?mfr=true
Graham

5157.

Solve : How to read a text file (Line by Line) using DOS??

Answer»

Hi Everyone,

In batch code, is it possible to read a text FILE (Line by Line).

For eg.,
Text file "Src.txt" CONTAINS the following text....
d:\a.txt
d:\b.txt
d:\c.txt

I NEED to read "src.txt" file line by line and i need to delete the file name mentioned in each line......, (Ie.., when dos read the FIRST line of "Src.txt" it should delete the file "D:\a.txt")

Is there any option to resolve this issue....

Thank in Advance.

Ur,
Vinoth



I've not been able to figure this out (If it is at all possible)welcom

u can use the for COMAND like this

for /f "delims=" %%i in (Src.txt) do del "%%i"Thank you very much.

5158.

Solve : [SOLVED] redirecting output?

Answer»

oh, that's nice
Thanks
...
What do you know? I tried the first code you sent, and it worked(obviously).
Then I tried this:
Code: [Select](ECHO hiya >doesnotexist\notextfile.txt) 2>error.txt
and got a TEXT file called error.txt saying "the path couldnt be found" (ie the output i wanted originally)

dang...now I am even more curious

Thanks See my (edited) POST No. 12 above.
ooops
Sorry, but you edited it twice, so I thought you meant the first edit.....my bad

Thanks

Two-EyesQuote from: Two-eyes on September 12, 2009, 07:58:47 AM

ooops
Sorry, but you edited it twice, so I thought you meant the first edit.....my bad

Thanks

Two-Eyes

No, my bad, I forgot I had edited it twice (I can't remember what I wrote first!)I think the answer is, that you know where the echo command ends but cmd.exe does not

ECHO hiya >doesnotexist\notextfile.txt 2>error.txt

it THINKS this is the filename to echo hiya into:

doesnotexist\notextfile.txt 2>error.txt

But this way it KNOWS

(ECHO hiya >doesnotexist\notextfile.txt) 2>error.txt



ahhh yes. The assumption "what I know, it knows". I FALL quite a few times in that.
5159.

Solve : 2 Handy Tips?

Answer»

These are for Windows 2000/XP/Vista

Unlike PAUSE, which accepts any key, SET /P will only accept the Enter key.

Code: [Select]SET /P =Press Enter to continue . . .
Group commands for redirection:

To log the result of several commands, a commonly used METHOD is

Code: [Select]command1 > logfile.log
command2 >> logfile.log
command3 >> logfile.log
In Windows NT4/2000/XP command grouping can be used to simplify the code:

Code: [Select](
command1
command2
command3
) > logfile.log
Thanks for the tips From my experience, you don't need to create the log file first.Quote from: Carbon Dudeoxide on May 15, 2008, 07:09:04 PM

From my experience, you don't need to create the log file first.

Where did I say that you did? It depends (OBVIOUSLY) on what you want to do. If you want to create a new file each time, overwriting any other with the same name, then you WOULD use the > symbol. If you want to create a file if it does not yet exist, OR add text to the end if it does already exist, you would use >>.


Nice tips
5160.

Solve : using FOR /R and XXMKLINK to make shortcuts - syntax trouble?

Answer»

Hi, I'm trying to make a batch file to make .lnk shortcuts to all of my music collection.

I'm getting close! I can get FOR /R to walk the directory tree, but XXMKLINK is BEHAVING unexpectedly.

for /r "\\mr-f36\music\" %f in (*.mp3) do xxmklink.exe "./" "%f"

XXMKLINK is basically an updated version of shortcut.exe from the WIN2K Dev Toolkit.

Instead of making an appropriately named .lnk to each mp3, this just keeps overwriting mp3.lnk in the directory above me. Your command line passed to xxmklink seems a little short of arguments...

Code: [Select]Command syntax of XXMKLINK:

xxmklink spath opath [ arg [ wdir [ desc [ mode [ ICON[:n] ]]]]]

where

spath path of the shortcut (.lnk added as needed)
opath path of the object represented by the shortcut
arg argument string (use quotes with space, see below)
wdir path of the working directory (for "Start in")
desc description string (shown in Shosrtcut's Properties)
mode display mode (1:Normal [default], 3:Maximized, 7:Minimized)
icon[:n] icon file [with optional icon index value n]

In addition to the above, the following switches are supported
which can be placed in any position in the command line.

/p prompts before action
/q no output when successful (quiet)
/e checks error condition strictly

Here is all of the information you need...

http://www.xxcopy.com/xxcopy38.htm

Solved my own problem:

for /r "\\mr-f36\music\" %f in (*) do xxmklink.exe "%~nf" "%f"

Now I have a single directory full of .lnk shortcuts to my entire music collection.

5161.

Solve : How do I "force" machine to boot from CD via a DOS command??

Answer»

This is something I've spent days on the Net TRYING to get the answer to...

I was given an old Tecra 510CDT running Win98. The BIOS, strangely enough, doesn't have a 'boot from CD' option available... only FDD or HDD in various combinations. I upgraded to the latest BIOS (6.90) and that didn't fix this issue. Very strange.

I booted to DOS and tried getting a Windows upgrade CD to boot. No dice.

I did have some measure of success by BOOTING to DOS using an old HP Win95 boot floppy, which contains some proprietary code. By doing this, the Tecra was ready to read and load the OS from the CD drive.

was ready, at that point, to insert the Win2kPro CD and see if it would overwrite the existing HD, but didn't want to until I had the following question answered just in case I ruined the existing HD data in an irretrievable way.

I'm guessing that the command I seek is inside the HP boot disk, but I'm not quite that tech savvy.

So:
I need to wipe the HD and run fdisk etc. (which I know how to do), then perform a clean OS install, but need to get the exact DOS command to cause the machine to begin "reading" from the OS disc and install it to the newly cleaned HD..


What "simple" technique will get the job done?

Many thanks in advance.Edit the autoexec.bat file on the bootable floppy to point to the mounted CD Rom ( probably D: ) and execute the installer for the clean install of the OS. Be sure to add this at the end of the batch file if an autoexec.bat file already exists ( likely does ) since this a a system recovery/ emergency boot disk. Point the installer automatically to call to the D:\setup.exe is after the drive is mounted with the generic oakes CD driver.

Just add --


d:\setup.exe


to the end of the autoexec.bat batch instruction on a new line below everything ELSE. DaveLembke,

Thank you for the helpful reply. Your advice worked to get my Win95 and 98 SE discs to load automatically when I boot from the emergency diskette which was modified per your instructions, which were very good.

For some reason my Win2kPro disc, nor my LINUX disc, will boot however.

When trying to load the 2kPro disc, the message, "This program cannot be run in DOS mode" appears.

When trying to load the Linux disc, the message, "Bad command or filename" appears.

Both of these problematic discs will boot without a hitch in my other Windows machines however.

The 95 & 98SE discs are factory manufactured.

The 2kPro I burned as a backup, per Dell computer's instruction (so that I could put the original in the safe with the other discs - but the "factory" 2kPro disc has gone missing). I used the HP software that came with the HP CD burner.

The Linux disc was burned by a friend. Perhaps there is missing "code" at the start of the "burned" discs, even though they were burned utilizing different programs.

Any further suggestions?

Thanks in advanceWhat happens if you boot to the emergency diskette and then at the A: prompt type D: and hit Enter ( or whichever drive is the CD drive) then type setup and hit Enter ? ?

You may have to REM out the CD autorun line provided by David temporarily to test this....

Dell probably has some pre-loaded garbage that gets included when you followed their instructions.

If you could post a screenshot of Explorer view of that Win2K CD that would be helpful...patio,

Thank you for the reply. When I deleted the X:\setup.exe command from the boot diskette, and manually typed in the same at the DOS prompt, I received the same exact results... the same error messages as outlined above appear once again.

As far as a screenshot of an Explorer window.....haven't ever tried that. Would you give me the basic instructions on how to do that?

Thanks in advance.
Windows 2000 Pro has an option to create 4 floppy disks to initiate the install on systems lacking bootable CD roms. If you have another system up and running with a good floppy drive and 4 good floppy disks you can place the CD in the drive and build these 4 installation floppies.

The link below will show you how to do this without me having to draw it all out. It works well for older systems which can run Windows 2000 Pro, but are lacking a bios that supports cd booting.

http://www.studynotes.net/70part1.htmNice catch David...i had not mentioned that.
The files for the floppies are available at bootdisk.com.Dave and Patio,

As you both were replying to me this morning, I discovered the following command while Exploring the Win2kPro CD:

[X]:\i386\winnt32.exe

This command from the DOS prompt launched the OS install... however a message "your drive is missing SmartDrive..." appeared. As you all know, this program MAKES the Win2k install much easier.

I then found the Bootdisk folder containing the MAKEBT32.EXE program on the Win2k CD and made the 4 bootdisks that you all had recommended.

I should be fine from here.........should be, should be, should be...

Thanks to you both for your help!

Now if I can figure out how to get the Linux distro to install in a dual boot environment ..... You should just DLoad a new Distro and make your own...i suspect your friend didn't create it properly.
Ubuntu is a good one to start with.
If you head to their site they will send you up to 10 CD's for any platform for FREE.
The nice thing is they include a Live CD so you can run it from CD and see if all your hardware is recognised and operates before actually installing it.
Post back if you need more info on setting up a dual-boot configuration...

5162.

Solve : can we run more than three scripts at a time?

Answer»

Hi,

I have few ".vbs" scripts, in general i am USING batch file to run them by placing
"cscript path for the vbs script1"
"cscript path for the vbs script2"
"cscript path for the vbs script3"
"cscript path for the vbs script4"
if i place in this WAY all the scripts are running but they are running in sequence like script1 then script 2 etc.
is there any way we can run them in paralle? can we run all of them at a time.

thank youQuote

I have few ".vbs" scripts, in general i am using batch file to run them by placing

ok first you would have to BUILD the scripts into applications

Quote
if i place in this way all the scripts are running but they are running in sequence like script1 then script 2 etc.

yes this is possible by simply saying
Code: [Select]start "script1"
start "script2"
etc.
Quote
is there any way we can run them in paralle?

no srry, commands in batch cant be run similtaneously, because DOS reads batch files SEQUENTIALLY

5163.

Solve : Determining what is in a text file via batch?

Answer»

Hi all, how would i go about making a batch file that reads a text file, and if the text file contains a certain word, execute a certain action?

Eg. i want my batch file to check if text file EXAMPLE.txt has EXAMPLEWORD in it, and if it does i want the batch file to continue with the code, or not do ANYTHING if EXAMPLEWORD is not found.

Thanks in advance,

KamakCode: [Select]for /f "tokens=* delims=" %%v in ('type example.txt ^| find "EXAMPLEWORD"') do echo %%v

This example executes the echo instruction if the argument is found. You can change this to whatever instruction you want executed. The search for EXAMPLEWORD is case sensitive. Add the /i SWITCH to the find command to make it case insensitive.

Happy coding, I am sure findstr takes in a file as input
Code: [Select]findstr /I /G:file "STRING to SEARCH" && execute_command
Findstr takes a file or receives an input via a pipe as Sidewinder's example shows.
Quote from: Dias de VERANO on May 16, 2008, 09:35:26 AM

Findstr takes a file or receives an input via a pipe as Sidewinder's example shows.

yup, so using type would be unnecessary , not that its a big deal anyway Quote from: ghostdog74 on May 16, 2008, 09:14:21 AM
I am sure findstr takes in a file as input
Code: [Select]findstr /I /G:file "STRING to SEARCH" && execute_command

findstr /I "String to search" filename.txt>nul && execute_commandThanks all, you've been really helpful
5164.

Solve : Copying Windows text into DOS program?

Answer»

Hello !
Any help advice would be appreciated!

How can I copy text from a windows word processing document and paste it into a DOS program??

I'm sure it's PROBABLY not "do-able", but I'm so desperate, I had to ASK!!

Thanks!

JenniferMore information, please! What Windows word PROCESSOR, and what DOS program are you thinking of?

arlight this works in command prompt so it should WORK in any dos prog

first copy the text from the Word proccessor(asumming Microsoft Word) then just right click at the spot that you want to paste the text onto command prompt or watever dos prog ur usingHello,
Thanks for answering! I have many different word processing programs-microsoft works (several versions), MSWord, Quark, etc. I want to paste text into a highly specialized DOS program..it's written in FoxBase (I'm not sure what version)..

The text would be pasted within a program that is used for data entry.

Thanks so MUCH!!!!

Jennifer

any time

5165.

Solve : Serious help with BAT??

Answer»

Quote from: Helpmeh on September 02, 2009, 05:13:41 AM

Lol.

If Mother.see Me.shakeBaby then CreateNew.WooshingSound
End If

I don't KNOW what language that could be in. Vb maybe?
or C# or C++ (classes)Quote from: smeezekitty on September 01, 2009, 05:29:59 PM
time to get back on the topic
as i said
cd /D "C:\PROGRAM Files\RaycastingGameMaker\GameBitmaps\BBits\"
"Barney's Asylum Reloaded.exe" "endomdog"
should work perfectly because the C runtime will parse out the "s

Yeah, everytime i try these codes they open a command prompt briefly and then it closes and no programs open? Any more ideas?Quote
everytime i try these codes they open a command prompt briefly and then it closes and no programs open

smeezekitty is such an expert, (we are all in his thrall) I'm surprised his code does that!
FINALLY! I FIGURED OUT HOW IT'S DONE!!!!!!!!!!! Okay, everyone listen close. I saved the BAT in the same FOLDER with the game, edited the file name, and I entered into the bat:

start BAR.exe edomdog

IT WORKED! THANKS ANYWAY FOR ALL YOUR CONSIDERATION THOUGH!Quote from: TNovelist on September 12, 2009, 09:15:53 AM
I saved the BAT in the same folder with the game

4 pages. Quote from: Salmon Trout on September 12, 2009, 09:22:36 AM
4 pages.

Look, I'm sorry. I just screwed up again. I tried making a copy of the bat file and reediting the code in it to make my game run fullscreen and I changed the names of the bat. Now it says, "BAT.exe not found." when I try and run it. So I GUESS this forum thread isn't over. Sorry, just fixed it again. There was a space in the file name.Quote from: TNovelist on August 30, 2009, 09:30:21 AM
Okay, so u mean:
START"C:\Program Files\RaycastingGameMaker\GameBitmaps\BBits\Install\Barney's Asylum Reloaded.exe" edomdog

(edomdog is my cheat code for god mode)

I got the error message: Windows cannot find the file, "edomdog." Now what should I do?


Put edomdog inside quote marks after Barney's Asylum Reloaded.exe.

EDIT: Ooo I posted this a bit late.
5166.

Solve : Can i undo changes made to my dos-program?

Answer»

No SOURCE code.Quote from: gabrieltire on May 21, 2008, 05:50:44 AM

No source code.
But can you TELL which database product is used to hold your data ?

GrahamI believe it uses a btrieve file.http://www.pervasive.com/support/technical/btrv615/btr61dos.pdf
Anyone out there who has experience with btrieve files?
5167.

Solve : Check If Variable Contains Anything But Numbers?

Answer»

I have a batch program that you run like:
wait.bat 20 < That will wait 20 seconds.
It works with the help from VBScript but it brings up a window if there is an error which I wan't my own error message, so how can I check the %1 variable for ANYTHING but numbers?
PLZ HELP!

THANX!

Code: [Select]@echo off
if "%1"=="" goto error2
set /a sec=%1*1000
>%temp%\$$$.vbs echo WScript.Sleep(%sec%)
start /wait %temp%\$$$.vbs
goto end
:error1
echo Wait.exe
echo ------------------------------
echo ERROR#1: DO NOT USE LETTERS.
echo USAGE: wait.exe (seconds)
echo ------------------------------
pause
goto end
:error2
echo Wait.exe
echo ------------------------------
echo ERROR#2: NO SECONDS GIVEN TO WAIT.
echo USAGE: wait.exe (seconds)
echo ------------------------------
pause
:end

If it detects anything but numbers I would like it to goto :error1

When it's done I'm compiling with Quick BFC

[attachment deleted by admin]since you are using a hybrid, you can do CHECKING easily with vbscript function called IsNumeric(). use it somewhere before the Wscript.Sleep() line...
check my sig for vbscript MANUAL for more informationQuote from: gh0std0g74 on September 13, 2009, 05:34:17 AM

since you are using a hybrid, you can do checking easily with vbscript function called IsNumeric(). use it somewhere before the Wscript.Sleep() line...
check my sig for vbscript manual for more information

Thanx I'll try that after!
5168.

Solve : Capture multiple selected File Names in Text File?

Answer»

Hi All,

I am trying to develop one utility where in I WANT to capture NAMES of multiple selected files in windwos explorer using context menu I am able to capture file names into text file but I want to add one extra command for post processing which is repeating for every selected file. For eg.: If i select 10 files, this post-processing command is repeated 9 times. Below is my code, please help me correct it. Thanks!

:TOP
IF "%1"=="" GOTO END
::ECHO %saspath% -sysin %1 %options% >> names.txt
echo %1 >>names.txt
SHIFT
GOTO TOP

:END
echo %saspath% -sysin F:\share\Manohar\pgm\chklog_asg.sas %options% >> names.txt


I want the END portion to be executed ONLY ONCE and after I capture names of all files but its repeating n-1 times where n is number of selected files. Batch code is designed to run in the shell environment. There is nothing wrong with your logic when it gets the command line arguments from the command line, however something may be getting lost in the handover from the Windows environment to the shell.

Quote

For eg.: If i select 10 files, this post-processing command is repeated 9 times.

Is this always true? For instance if you select 5 files, do only 4 get passed? Seems odd that it would stop working when the parameters are no longer addressable. If that's true then this piece of code won't help, but hey you never know!


Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ("%*") do (
set str=%%v
)
set /a count=1
:top
for /f "tokens=%count%" %%v in ("%str%") do (
echo %%v >> names.txt
call set /a count=%%count%%+1
goto top
)
:out
echo %saspath% -sysin F:\share\Manohar\pgm\chklog_asg.sas %options% >> names.txt

Perhaps to can give us more info on how this batch file is connected to explorer and what prompts it's execution.

Hi,

Thanks! for your reply. But the issue still exists. To give you idea about how this batch file is executed, I went to Tools->Folder Options->File Types->.sas( SAS Program) -> Advance -> ChkLog(menu item)

I have following command pasted : F:\Share\Manohar\copy.bat "%1" in action perfomed box.

What I basically want to do is get names of selected .sas programs, execute them and check their log files. When I run your code below is the OUTPUT I am getting
"F:\Share\manohar\v_adhy.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
"F:\Share\manohar\v_adfb.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
"F:\Share\manohar\v_adfh.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
"F:\Share\manohar\v_adhb_29feb.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
"F:\Share\manohar\v_adhb_sure.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon

You can see that chklog_asg.sas program is selected multiple times. All I want is to be selected once and that too at the end. Is it has to do with %1 parameter which I pass in action performed box. I even tried to remove that %1 but windows by defualt enter it again. Please provide your input. Thanks!I seem to remember to something a similar way back. For some REASON the "%L" variable was used on the command line in Windows.

Try using open in the action box and in the application used to perform action box USE "F:\Share\Manohar\copy.bat" "%L". And make sure the DDE box is checked.

Seems the %L is a system variable used in Windows Explorer.

Hi,

Thanks! again for your reply. But no LUCK. It still executes the :out code n number of times. The output still is:

"F:\Share\manohar\v_adhb_29feb.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
"F:\Share\manohar\v_adfb.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
"F:\Share\manohar\v_adfh.sas"
"C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon

Not sure which batch file you're using. (yours or mine posted earlier). In any case add a pause statement at the end, make sure echo is off, and post the console listing.

Something does not make sense; if each file selected is run thru a batch file separately, there should be n number of post processing commands, not n-1. If the files are submitted to the batch file as a group then I can find not an error in your original logic. Maybe the console list will give us some insight.

5169.

Solve : copy data step by step?

Answer»

I am new to the batch scripting. Can anyone plz tell me what would be the script of following task

Copy Floppy Disc (main heading)
1. Put in floppy disc [ready for copy]
2. Press Enter key to START copy all DATA from floppy disc into the choice folder in the hard disc [C:\temp_floppy]
3. Upon finish, display message
i. Please insert new floppy disc [Y /N]
ii. Do you want to cancel this operation [Y /N]
Quote from: Adeel on September 11, 2009, 05:55:15 AM

I am new to the batch scripting. Can anyone plz tell me what would be the script of following task

Copy Floppy Disc (main heading)
1. Put in floppy disc [ready for copy]
2. Press Enter key to start copy all data from floppy disc into the choice folder in the hard disc [C:\temp_floppy]
3. Upon finish, display message
i. Please insert new floppy disc [Y /N]
ii. Do you want to cancel this operation [Y /N]


1. Put in floppy disc into drive [ready for copy]
( There is no software command for this task )


C:\>D:

D:\>copy *.* c:\temp_floppy\

Quote from: billrich on September 11, 2009, 07:29:43 AM
1. Put in floppy disc into drive [ready for copy]
( There is no software command for this task )

I think he means display a message to the user to insert a DISK

Code: [Select]@echo off
:loop
cls
echo Insert a floppy disk and then
set /p dummy=press ENTER to start copying
copy a:\*.* c:\temp_floppy
set /p again="Do you want to copy another disk [Y/N] ? "
if /i "%again%"=="Y" goto loop

Thanks mate, your script is working

Actually i m working on project, two more things are yet to do. Can you help me out plz

1. Enter new Directory name
b. Confirm new Directory by [Y /N]

2 - Generate list of folder and file on particular directory

1.

Code: [Select]:loop
set dirname=
set /p dirname="Enter directory name ? "
if /i "%dirname%"=="" (
echo Error: empty input.
echo.
goto loop
)
echo.
echo You entered %dirname%.
:check
set /p correct="Is this correct [Y/N] ? "
if /i "%correct%"=="Y" goto next
if /i "%correct%"=="N" (
echo.
goto loop
)
echo Error: type Y or N only!
echo.
goto check
:next

2. DIR directory

really APPRECIATE your time and effort... but still the required task is not done

In FIRST task, the entered folder name is not being created actually

and

in second task how to generate a list of text files and directories with that command..

will be waiting

thanxQuote from: Adeel on September 13, 2009, 07:37:37 AM
but still the required task is not done

In first task, the entered folder name is not being created actually

and

in second task how to generate a list of text files and directories with that command..


1. You did not say you wanted to create a directory. Study the mkdir command.
2. To learn how to make a list of files and directories, study the dir command. Quote from: Adeel on September 13, 2009, 03:56:07 AM
Actually i m working on project, two more things are yet to do.

This wouldn't be a school project would it?
5170.

Solve : Answering yes when a bat file runs?

Answer»

I am building a bat file to setup .net framework to run. When the command runs it ask if you are sure, it has a y & n. I want it to select y and run from there. does the .net framework install file support command line switching???

if so there might be a slient switch.

the best way to find out is to open the command prompt and loacte said install file, then;

c:\loaction\of\instal\file\setup.exe /?


hope it helps.I deleted my earlier post. Apparently I misunderstood the QUESTION. If indeed the program is called setup, you can use the pipe to forcefeed the response.

Example: echo Y | setup.exe

Note: not all PROGRAMS are written to accept data from the pipe.

CHOSE = command 1 needs.
If 1 does not've DOS 6 1 still has chose ;-)
YN or ASK? or others.
Or CHOSE = included + G.E.M. @ shaneland. llightsey,
Go to the CMD window and try blastman's & Sidewinder's suggestions.
You may find that there is a silent switch, or you may be able to echo the y as Sidewinder suggested. Then you can incorporate the solution in you batch file.


Quote from: AndrewH on May 17, 2008, 05:37:02 AM

CHOSE = command 1 needs.
If 1 does not've DOS 6 1 still has chose ;-)
YN or ASK? or others.
Or CHOSE = included + G.E.M. @ shaneland.

Andrew,

I think you meant Choice.com from DOS, NOT "CHOSE"
Besides that, I don't think choice will help llightsey out here.

blastman & Sidewinder both have viable suggestions that llightsey should pursue first.

This is the bat file i want to run, when it runs it ask if i am sure and I answer YES. I don't want to type the yes in how can I make it auto answer the question and run?

Bat file to allow a PC to run .net programs
color 0a
@cls

c:
cd \windows
cd microsoft.net
cd Framework
cd v2.0.50727
CasPol.exe -m -ag 1.2 -zone Intranet FullTrust set
set PERSIS=/PERSISTENT:YES
pauseDid you research if there is a silent switch? You can try the pipe but there are no guarantees:

Code: [Select]c:
cd \windows\microsoft.net\Framework\v2.0.50727
echo Y | CasPol.exe -m -ag 1.2 -zone Intranet FullTrust set
set PERSIS=/PERSISTENT:YES
pause

If the program is expecting the fullword YES, then echo YES instead of Y.



Any reason the set statement is after the program execute?

Sidewinder, it still wont run unless you type the YES inWell, like I mentioned, not all programs take input from the pipe. Unless you can find a switch for the program to run silently, you may SOL.

Have you tried running the program from the Windows run box?

Code: [Select]"c:\windows\microsoft.net\Framework\v2.0.50727\CasPol.exe -m -ag 1.2 -zone Intranet FullTrust set"

It might be interesting to see if the shell gets activated for the prompt. You can set PERSIS anytime either temporarily thru the batch shell or permanently thru Windows.

Good LUCK. I got it working I found the switch that TURNS the question off
New Code

Bat file to allow a PC to run .net programs
color 0a
@cls

c:
cd \windows\microsoft.net\Framework\v2.0.50727
CasPol.exe -pp off -m -ag 1.2 -zone Intranet FullTrust

Just change the _pp on and it will agin ask you It's always good to hear to success STORY. Thanks for all your help on the Fourm Sidewinder
5171.

Solve : using telnet in a batch file?

Answer»

Greetings,

I'm trying to use telnet in a batch file.

-The batch file will telnet to a machine
-ENTER username and password
-Execute a few command
-Log output to file then exit

I can not get pass the telnet command

Once the telnet is EXECUTED I can not enter the user name and password.

Help.

Here is what I have so far

@ECHO off
echo Ping test for port

telnet 10.10.10.17

admin

admin

Output of PROGRAM:

SunOS 5.9

login:

what app are you trying to run?? Is the remote machine windows based??

if so you can use the freeware, pstools.

pstools has a little exe called psexec which allows you to run PROGRAMS on a remote machine. (very handy, and all from the command prompt)

I've used it loads.

Hope it helps.

Info and donwload link;

http://www.microsoft.com/technet/sysinternals/Security/PsTools.mspx

5172.

Solve : A simple batch file, lots of confusion?

Answer»

Heya, I'm back. I've been studying up a bit on my coding and programming and someone asked me a question. The question was "Could that remote shutoff denial program you made be reversed to close explorer?". I shrugged and said something along the lines of "Probably, but I'd just write something different.". Eventually the curiosity overcame me and I tried it. It didn't work. My code is as follows:

Code: [Select]@echo off
:start
taskkill /im explorer.exe /f /t
goto start
Bugs/issues:

  • Closes all expected files (explorer and folders) as well as Windows MEDIA Player
  • Only runs once; possibly self terminated by the explorer shutdown

No rush on getting back to me. At least this time I gave it some thought. If this won't work, is it possible to create a file that runs only when explorer is opened?when you say, "explorer" do you mean the windows explorer or the internet explorer???Quote
Bugs/issues:

* Closes all expected files (explorer and folders) as well as Windows Media Player
If you end the Explorer.exe process, you can expect to 'screw' up your COMPUTER.

What exactly are you trying to accomplish by doing this?Quote from: blastman on June 02, 2008, 07:55:09 AM
when you say, "explorer" do you mean the windows explorer or the internet explorer???
Windows explorer.

Quote from: Carbon Dudeoxide on June 02, 2008, 07:56:35 AM

If you end the Explorer.exe process, you can expect to 'screw' up your computer.

What exactly are you trying to accomplish by doing this?

HRM... I guess Media Player -should- close? That may be a hint to a problem on this computer then. Usually when I close explorer through things LIKE task manager, most other programs remain running. Yes, folders close, but programs usually remain open.

Ideally, only explorer should close.

As for what I'm trying to accomplish, I just want to see if it can be done. My friend NATE asked and I want to see if it can be done.
5173.

Solve : Resize Partition...?

Answer»

I have windows XP SP2. How can I resize my hard drive partition using DOS ?NTFS or FAT?

And why in Dos???

Have a look here for freebie utilities.

Good luckNTFS Partition.
I want to do in DOS bcoz softwares like Partition magic pro 7.0 are not running properly on my system. They all hang in midst.

Do u know wht could be the reason ?Seems likely you could have a software or hardware problem - do you get any error reports or other hangups?

Is your backup up-to-date? Are there any critical FILES on your hard drive which you cannot afford to lose? If anything GOES wrong when ALTERING partition sizes file content may be lost.

Ya, I get blue screen error when I resume from standby. nd also sometimes my system gets hanged up while i'm playing games or doing other work.

Please give sol
Here's a screenshot :::

[recovering space - attachment deleted by admin]I hope you have everything backed up!

You could lose all your data if one of your attempts gets half way done when it hangs.

I've never lost anything with Partition Magic, but they all WARN you of the possibility of data loss.Quote from: nit.1762 on June 01, 2008, 04:07:06 AM

Ya, I get blue screen error when I resume from standby. nd also sometimes my system gets hanged up while i'm playing games or doing other work.

Please give sol


It is likely that your hard disk is about to fail or that at least one stick of your ram is already defective. If it is the former then you may be about to lose all files on your hdd. Please get back and tell us that your backup is secure.

Download and run the diagnostics program from your hdd manufacturers site, if the program indicates a failure then you have no alternative to replacing your hdd. Also d/l & run Memtest86 from Memtest.com.

If you get another bsod post the ENTIRE error message not just what you remember of it.

Good luck.

5174.

Solve : how run command prompt without displaying black screen?

Answer»

hello everyone ,

how can i RUN test.bat file without displaying anything to the user i mean that black screen not showing


thanks This question has been asked before. Even commercial developers have a hard time doing that. Those who ask this question often are people who wish to do secret and harmful things ot other peoples computers.
We would like to help, but there is no easy answer we can offer. There is little reason to hide a DOS box from the user if it is only going to be there for a second or two.

Powerful programs that must run in the BACKGROUND are made using guidelines in the SDK (Software Development Kit) from Microsoft. It is beyond the general scope of this forum to help people with making system level programs.

But if you want to learn more about the Microsoft SDK. here is a link to free information and a tutorial.
http://quickstarts.asp.net/QuickStartv20/default.aspx
Still don't understand why it has to be silent...If it's in an office, just display that the window shouldn't be closed as it is for their benefit or something.It's not because of you that we can't reveal how to make batch files run invisibly, it's because if someone who has bad intentions get's HOLD of it, they could do some nasty things.emulhulk, the question isn't merely about wether you need this for a legitimate use. remember this forum is available from the internet, publically. to anybody. If somebody were to encounter this THREAD (and somebody HAD provided an answer to run a batch file silently) then there is no telling wether they will use it for malicious intent.

Additionally being here for less then a day and telling people who have been here for years how to conduct themselves- and members of the forum staff, no less, is nothing short then inexcusable. To even suggest that your grasp of the "rules" of the forum is greater them somebody who has both followed and enforced them for years is nothing short of amazing.


There was nothing wrong with your question. The more questions like this exist, the more likely someone will see our answer, so the less likely they will post the same question!

Wierd, but it WORKS somehow lol!To emuhulk
Glad to see your apology.
If you really need the answer to your original question, this is the best forum there is to help people who are new to computer management.
The security issue is a very important concern.

BC_Programmer is the one here that can best help you. He knows how to do want you want. But the answer is not what you expect. And he would tell you there is not simple way to hide the presence of batch files because there is almost no need to do it in secret. Even some programs from Microsoft will show the DOS scream until done. The most piratical answer is to re-write the program in a system language, like C and compile it to run as a background task. I would guess that would be what BC woul tell you, if you asked him in a very nice way.

A Google search shows the question has come up years ago and nobody had a easy answer. Batch files are not well suited for running without any visibility to the computer user.

Quote from: Geek-9pm on September 12, 2009, 09:04:29 PM

To emuhulk
Glad to see your apology.
If you really need the answer to your original question, this is the best forum there is to help people who are new to computer management.
The security issue is a very important concern.

BC_Programmer is the one here that can best help you. He knows how to do want you want. But the answer is not what you expect. And he would tell you there is not simple way to hide the presence of batch files because there is almost no need to do it in secret. Even some programs from Microsoft will show the DOS scream until done. The most piratical answer is to re-write the program in a system language, like C and compile it to run as a background task. I would guess that would be what BC woul tell you, if you asked him in a very nice way.

A Google search shows the question has come up years ago and nobody had a easy answer. Batch files are not well suited for running without any visibility to the computer user.



well actually- it's a one liner in both vb6 and vbscript.Quote from: emuhulk on September 12, 2009, 08:33:40 PM
forum that i tought it can help to develope my project for my internship.

See now it's homework and that's frowned upon in here.
If it's homework then ask and explain exactly what it is YOU have done to find the answer. I love google but it costs my neighbours a lot of money to keep me on the internet..Download the app in the attatchments I made, drag a batch file onto it or run like: INVISIRUN.exe PROGRAM.bat
It will run the batch program invisible.
-----------------------------------------------------------------------------------------------------------------------------------------------
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
Free compiling software to convert .bat to .exe, you can click Invisible Application to make it invisible.
-----------------------------------------------------------------------------------------------------------------------------------------------
Do not use Invisirun.exe for HAX0R batch files as I am not responsible for any damage caused to any comps.


elel302

[attachment deleted by admin]Quote from: elel302 on September 13, 2009, 08:59:57 AM
Download the app in the attatchments I made, drag a batch file onto it or run like: INVISIRUN.exe PROGRAM.bat
It will run the batch program invisible.
-----------------------------------------------------------------------------------------------------------------------------------------------
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
Free compiling software to convert .bat to .exe, you can click Invisible Application to make it invisible.
-----------------------------------------------------------------------------------------------------------------------------------------------
Do not use Invisirun.exe for HAX0R batch files as I am not responsible for any damage caused to any comps.


elel302
Please delete that post.
5175.

Solve : Help please!!!!!!!?

Answer»

Hi, I'm new here, so hi everyone!

This may be simple question, I hope!

AJ
I have, like alot of people, alot of classic dos games (Sierra On-Line anthologies etc). Ok, here's the problem.Since xp is not dos friendly, I'm running windows 98se on a different computer without a problem but this. I have a soundblaster live digital 5.1, the problem is two THINGS, where do I get the last DRIVER pack, and especially the command line... without the command line, the programs will not work.

Help me please!
I have my old dos games running on vista using DOSBOX (http://www.dosbox.com/). it emulates a dos evironment for applications and games and this would work on your xp computer as well. There is also vdmsound (http://sourceforge.net/projects/vdmsound/) which just emulates the sound driver for dos. It supports sound BLASTER and adlib cards so chances are yours would be supported. Id try them both out and see if either works and which you prefer.Yeah, I have it, but I'd rather use my SECOND comp for dos
thanks
anyway
AJ!

5176.

Solve : Memory Map HELP?

Answer»

Quote from: nymph4 on May 15, 2008, 12:26:14 PM

Am I CORECT that you would need both EMM386.EXE and HIMEM.SYS to use Extended Memory?

Yes. The HIMEM.SYS line must appear before the EMM386.EXE DEVICE line in CONFIG.SYS.

This thread looks like you are studying for your A+ certification. I hope you are not doing all your learning on web forums!
Quote from: Dias de verano on May 15, 2008, 12:36:14 PM
Quote from: nymph4 on May 15, 2008, 12:26:14 PM
Am I corect that you would need both EMM386.EXE and HIMEM.SYS to use Extended Memory?

Yes. The HIMEM.SYS line must appear before the EMM386.EXE DEVICE line in CONFIG.SYS.

This thread looks like you are studying for your A+ certification. I hope you are not doing all your learning on web forums!


To emulate EXPANDED memory, yes, to use extended memory no- Otherwise the 286 would have NEVER been able to use extended memory, since it can't use EMM386. (which might explain the name)


And the EMM386 program can be run standalone, and will give some information and/or change settings when passed switches.


why, I even fired up my old thinkpad just for you guys

emm386 when run as a command gives me this:


IBM Expanded Memory Manager 386 Version 4.50
Copyright (c) IBM Corp. 1986, 1994

Expanded memory services unavailable.

Total upper memory available . . . . . . 0 KB
Largest Upper Memory Block available . . 0 KB
Upper memory starting address . . . . . . B000 H

EMM386 Active.


and probably my most used command usually, mem /c, gives:

[t]MODULES using memory below 1Mb:

Name Total = Conventional + Upper Memory
-------- ---------------- ---------------- ----------------
SYSTEM 22,928 (22K) 9,616 (9K) 13,312 (13K)
HIMEM 768 (1K) 768 (1K) 0 (0K)
EMM386 3,392 (3K) 3,392 (3K) 0 (0K)
V7320MGR 2,096 (2K) 2,096 (2K) 0 (0K)
V7320APM 1,696 (2K) 1,696 (2K) 0 (0K)
DOSKEY 1,152 (1K) 1,152 (1K) 0 (0K)
MOUSE 24,576 (24K) 272 (0K) 24,304 (24K)
COMMAND 3,424 (3K) 0 (0K) 3,424 (3K)
FDREAD 160 (0K) 0 (0K) 160 (0K)
ANSI 3,600 (4K) 0 (0K) 3,600 (4K)
MWDP0400 2,032 (2K) 0 (0K) 2,032 (2K)
FREE 742,416 (725K) 636,352 (621K) 106,064 (104K)

Memory SUMMARY:

Type of Memory Total = Used + Free
---------------- ----------- ----------- -----------
Conventional 655,360 19,008 636,352
Upper 152,896 46,832 106,064
Reserved 240,320 240,320 0
Extended (XMS) 7,340,032 380,928 6,959,104
---------------- ----------- ----------- -----------
Total memory 8,388,608 687,088 7,701,520

Total under 1Mb 808,256 65,840 742,416

Total Extended (XMS) 7,340,032 (7,168K)
Free Extended (XMS) 6,959,104 (6,796K)

Largest executable program size 635,376 (620K)
Largest free upper memory block 67,856 (66K)
Available space in High Memory Area 3,568 (3K)
PC DOS is resident in the high memory area.[/tt]

5177.

Solve : checking service status?

Answer»

Hi,

I'm new to dos batch scripting. I'm just trying to write a script that will check the status of a service and then depending on the status, give the option to either start or stop it. I have the following to check the current status. The problem is that it works find when the service is running. If I stop the service and then run this script, it doesn't work. DOS window comes up and quickly disappears.

If the service is running already and I run the script, it works. While the script is running, if I stop the service manually and then press any key to check the status again, it still shows that the service is running, which is incorrect.

Could you kindly show me what I'm doing wrong. As I'm new to this, I'm sure I'm missing something simple. Thanks for your help.
Code: [Select]@echo off

set svc= apache2.2

:main
call:check_services val
echo %val%
pause
goto:main

:check_services

sc query %svc% | find "RUNNING">nul && set svcRunning= Yes

if %svcRunning% == Yes (
set %~1= Running
) else (
set %~1=Not Running
)

goto:eofIn terms of pure syntax, these things need fixing...

Code: [Select]set svc= apache2.2
Remove space before apache unless you really have a reason to need it

Code: [Select]call:check_services val
1. Insert space after call and before :check_services
2. What is 'val' doing there?

Code: [Select]sc query %svc% | find "RUNNING">nul && set svcRunning= Yes
Remove space before Yes (see above)

Code: [Select]if %svcRunning% == Yes (
Enclose %svcRunning% and Yes in quotes, and remove the spaces

Code: [Select]set %~1= Running
? You cannot set variables like this!

However, I think you have made things too complicated for yourself. All that CALL stuff. Too many variables. So many extra possibilities for confusion. Simpler is better. Why not do it this way:

1. Set your message to "not running" or "no" or "0" whatever.
2. Check if the service is running.
3. If it is running, change the message to "running" or "yes" or "OK" or "1" or whatever.
4. If it is not running, leave it alone.
5. Test the message & perform actions depending on the result.

Code: [Select]@echo off
set svc=apache2.2
set svcRunning=not running
sc query %svc% | find "RUNNING">nul && set svcRunning=running

Now you can do your checking

Code: [Select]echo Service %svc% is %svcrunning%.
if "%svcRunning%"=="running" (
REM do stuff if it is running
REM can be more than 1 line
) else (
REM do stuff if it is not running
REM can be more than 1 line
)

Personally I often use the & symbol to join 2 lines together if they are meant to always follow each other, like this

Code: [Select]set svcRunning=not running&sc query %svc% | find "RUNNING">nul && set svcRunning=running
Some tips sincerely meant to be helpful...

-- avoid using chains of variables like this

Code: [Select]if "%something%"=="%something_else%" set variable=OK
if "%variable%"=="OK" do_something
when you could just do

Code: [Select]if "%something%"=="%something_else%" do_something
of course if you need to test more than once then %variable% serves some purpose, but if it doesn't then it's just pointless code. I think I learned this habit when BASIC programming in the 1980s when memory was expensive (64K was a lot!) and since every variable used some memory, you had to be sparing. I know that memory is cheap nowadays but the more simple and readable you make your code, the easier it will be for to figure out what's going on, and the LESS time you will spend unravelling things when your code does not do what you want. Especially if you have a dozen variables all with similar names!

In short, get your ideas straight about what you want the batch to do, and then write the code, rather than trying to do both at once. Don't (as you sometimes see on here!) write the code first and work out what you want it to do afterwards.

Hi Dias,

Thanks so much for all the tips, suggestions and most importantly, time. You are right, I made it a little more complicated than it should've been. I CLEANED it up a bit.

Code: [Select]call:check_services val
I was trying to pass parameter to check_services function so that I don't have to run multiple query line in there and use val INSTEAD in one line by accessing this val as "%~1" in check_services function. This way I can call that function multiple times and I won't have to have separate variables for each. But I think, that's too complex for batch. So, I got rid of that idea and now have two lines of query in check_services(since I'm checking for two different services).

I actually found my initial problem. I NEEDED to reinitialize a variable because
Code: [Select]sc query %svc% | find "RUNNING">nul && set svcRunning= Yesthe above will only set svcRunning to "Yes" only when the service is running. And while the batch script is running, if I manually stop the service, then my script doesn't set svcRunning to "No". It uses the old value which is still set to "Yes". This is why, when I manually stop the service and call the check_services again, it wasn't showing the correct results.

Could you kindly tell me what is wrong with the following. Since I'm new to this, I pretty sure I just don't have the correct syntax. When my script reaches this if statement, it just bombs out. If I have one condition in the if statement, it works fine. Googling right now to find out how to COMBINE two if statements into one. Haven't found anything yet.

Code: [Select]if "%svc1_Running%"=="No" && "%svc2_Running%"=="No" (
rem show option to start both services
) else (
rem show option to stop both services
)
Thanks again for your help.Quote from: pman on May 31, 2008, 12:27:15 PM


Code: [Select]call:check_services val

I was trying to pass parameter to check_services function so that I don't have to run multiple query line in there and use val instead in one line by accessing this val as "%~1" in check_services function.

OK but it should be %val%

Quote
Could you kindly tell me what is wrong with the following.

&& doesn't do what you think it does.

This should work...

Code: [Select]if "%svc1_Running%"=="No" (
if "%svc2_Running%"=="No" (
rem show option to start both services
goto next
)
)

REM show option to stop both services

:next



code]

[/quote]
5178.

Solve : can i open a dos program without ............?

Answer» HI all,
just wondering if its possible to install and open a dos program without having windows installed and if so how?
thanksYes...you could have DOS installed on the hard drive to handle the DOS program on the CD or Floppy. Best version of DOS is 6.22 for its features and compatability. If you dont have this you can buy a OEM install set of about 4 or 5 floppies off of ebay, or if you want a free solution you can use FREEDOS which is open source at http://www.freedos.com/

http://www.freedos.org/

Here is the ACTUAL URL to FREEDOSgreat stuff thanks for all your help! If using W95/8, ME or XP (but not 2000) make a start-up floppy.
copy EDIT &c from C:\WINDOWS\COMMAND.The suggestions given are all on track, but I'm curious.

Are you working with an older COMPUTER that doesn't have windows installed?
Or are you TRYING to get an older DOS program running that doesn't seem to run from Windows?
5179.

Solve : Can you make a batch file save a notepad file??

Answer»

Hi all.

I was wondering if i COULD run a batch file to save something LIKE a NOTEPAD document i have on the screen.

Is this possible? and if so, how?

Thanks in advance,

KamakNot sure what you mean. Why don't you just choose File, Save in Notepad?
Well, i was TRYING to automate that bit, but i found a way to do it with vb SCRIPT, so it's all good

5180.

Solve : echo %name% displays echo is off message ?????

Answer»

hello

ECHO %name% displays echo is of message instead of printing the "name" to screen name is input is was like that SET /p name=enter name: Is this your CODE?

Quote

REM Displays echo is of message
set /p name=enter name:
echo %name%

Seems to work for meQuote from: emuhulk on September 10, 2009, 12:48:13 PM
actually what happens is that when put echo inside if statemet it doesnt display ANYTHING it says echo is off

if you are using parentheses you need to study delayed expansion. Search this forum or use Google.
Quote from: emuhulk on September 10, 2009, 03:52:01 AM
hello

echo %name% displays echo is of message instead of printing the "name" to screen name is input is was like that set /p name=enter name:

Maby %name% has no value or was not set properly.
5181.

Solve : Loading From A Different Folder.?

Answer»

Well, i have stopped the whole loading from a .TXT file, and i am now loading by seeing if the file exists. So far i have this:
Code: [Select]@echo off
if EXIST level2.txt (
set level=2
) else (
set level=1
)
if EXIST level3.txt ==if EXIST level2.txt (
set level=3
) else (
set level=1
)
if EXIST level4.txt ==if EXIST level3.txt ==if EXIST level2.txt (
set level=4
) else (
set level=1
)

echo.
echo Player Level = %level%
PAUSE >nul

Instead of having the files in the same folder as the .bat
how would i MAKE it so it read from a sub-folder like \data\level4.txt.

Any Help Appreciated.Quote from: Jacob on May 31, 2008, 03:27:58 AM

i have this:
Code: [Select]if EXIST level2.txt
how would i make it so it read from a sub-folder like \data\level4.txt.

Code: [Select]if EXIST data\level4.txtallready tried it, it doesn't work.Are you sure you are doing it properly? It works for me. Try the drive letter and full path.

Remove the first slash if the data folder is under the folder you are in when you run the batch

if EXIST data\level2.txt

Provide the full drive letter and path, with quotes if any part has spaces

if EXIST "C:\My Files\Jacob\whatever\data\level2.txt"

That should always work.

----------------------------------------

This will NEVER work.

Only 1 IF test per line! I don't know why you put == in there!

Code: [Select]if EXIST level3.txt ==if EXIST level2.txt (


Thanks Very Much, I had to do "data\" instead of "\data\"Quote from: DIAS de verano on May 31, 2008, 04:39:24 AM

This will NEVER work.

Only 1 IF test per line! I don't know why you put == in there!

Code: [Select]if EXIST level3.txt ==if EXIST level2.txt (

it does, its saying that both of them have to exist so if you want level 3 the level 2 and level 3 files have to be in there. instead of just having one level 3 file.

It seems to work and i have tested it.Quote from: Jacob on May 31, 2008, 04:50:47 AM
It seems to work and i have tested it.

Yes it does! I never knew you could do that. Sorry!
Quote from: Dias de verano on May 31, 2008, 04:57:03 AM
Quote from: Jacob on May 31, 2008, 04:50:47 AM
It seems to work and i have tested it.

Yes it does! I never knew you could do that. Sorry!

It's fine, looks like we helped each other, at first i tried &AMP;& with no success i then tried == and woula!.

Thanks Again
5182.

Solve : How run a vb script inside a Ms dos batch script??

Answer»

I have this .bat file script but the sent.vbs is not executing inside the bathc.
The sent.vbs executes perfectly from the "COMMAND prompt".

I don't know how to get to execute the vb script based on the "for", see:

set newDate=%date:~4,2%-%date:~7,2%-%date:~10%
for /f "delims=" %a in ('findstr /i /s "ORA- rejected EXP- ANS1312E ANS1329S failure FAILURE" c:\oracle\admin\secmonit\logs\exports_logs\export_db_secmonit_%newDate%.log') do (c:\oracle\admin\secmonit\scripts\sent.vbs)

The file export_db_secmonit_05-17-2008.log has an ANS1329S error inside of it.

you can try specifying cscript when you call your VBSCRIPT. however why should you do that when you can do all in vbscript
Code: [Select]YR = Year(Now)
mth = Month(Now)
If Len(mth) = 1 Then
mth = "0"&mth
End If
If Len(dday ) = 1 Then
dday = "0"&mth
End If
dday = DAY(Now)
NewDate = mth &"-"&dday&"-"&yr
Set objFSO =CreateObject("Scripting.FileSystemObject")
strMyFile = "C:\test\your_oracle_file"
strPattern = "ANS1329S failure"
Set objFS = objFSO.OpenTextFile(strMyFile)
Do Until objFS.AtEndOfLine
strLine = objFS.ReadLine
If InStr(1,strLine,strPattern) > 0 Then
WScript.Echo strLine
' sent.vbs code here.
End If

Loop
Thank you ghostdog74. The cscript worked.

5183.

Solve : Complicated batch file?

Answer»

What I need is a batch file that can delete CERTAIN folders when given ANSWERS to certain questions.

Example: I have folders named a to z within another folder. I want the batch file to ask which I want, so I type a. The batch file then removes all other folders, leaving me with only a.
Is this possible to ACCOMPLISH using batch? It sounds complicated to me but it may not be, I know a little batch but not much.This code is generic to check the first letter of each folder.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set /p var=Enter Folder Letter To Keep:
for /f "tokens=* delims=" %%i in ('dir /a:d /b foldername') do (
set FNAME=%%i
set ltr=!fname:~0,1!
if /i !ltr! NEQ %var% rd %%i /s /q
)

Change foldername to something appropriate for your system.


Thanks for that, I'll give it a shot.
I may end up posting back needing modifications, I deliberately didn't give the full picture because I want to learn how to do as much as possible myself, and there's a lot I need to accomplish with this batch file.

5184.

Solve : Renaming files in a folder depending on size and order?

Answer»

Hello, I am new to this list and hope to find some help with this.
I am using Windows server 2003 and XP and need a bat file that can do the following if it is possible.
The files are in a folder lets say "D:\testfiles" and has to be copied to a new folder "D:\updates" and also renamed
I have in the "testfiles folder" files that looks like this:
test_20.id
test_20.ind
test_20.map
test_20.dat
test_21.id
test_21.ind
test_21.map
test_21.dat
etc etc...

I need them to be copied to "updates" and renamed to line1, line2, line3, line4, LINE5, line6, line7... etc in numerical order that always start with "1"
End result must be like this
line1.id
line1.ind
line1.map
line1.dat
line2.id
line2.ind
line2.map
line2.dat
etc etc...

The problem is that the filenames in the "testfiles" folder change so next time could be like this or even higher numbers, (they are always in numerical order):

test_72.id
test_72.ind
test_72.map
test_72.dat
test_73.id
test_73.ind
test_73.map
test_73.dat
etc etc...

As I have a bat file with "rename" function I need to check the names in the "testfiles" folder first and then edit the batfile so it has the correct filenames. This is a bit boring and time consuming as it can be up to 40 - 50 files. Is there a WAY to solve this in an easier manner?

Also it is a "group" ( for example test_72.*) of the files that is of no interest as they have a max total of 25 Kb, can they be sorted out and be removed from the process? Is this possible with a bat file to calculate total size of a group of files with the same name (except for the file type) and remove it, if it is below a specified size?

Regards
Soren


This comes dangerously close to programming and batch coding is really not suitable for this if for no other reason than for maintenance.

Code: [Select]@echo off
setlocal
set /a lines=1

for /f "tokens=1-3 delims=e." %%i In ('dir /o:-n /a:-d /b d:\updates') do (
set lines=%%j+1
goto out
)

:out
set /a count=0

for /f "tokens=* delims=." %%v in ('dir /a:-d /b d:\testfiles') do (
call :group "%%v"
)

:group
call set /a count=%%count%%+1
if %count% GTR 4 (
set /a count=1
call set /a lines=%%lines%%+1
)
for /f "tokens=1-2 delims=." %%w in ("%1") do (
copy d:\testfiles\"%1" d:\updates\line%lines%.%%x > nul
)


Quote

Also it is a "group" ( for example test_72.*) of the files that is of no interest as they have a max total of 25 Kb, can they be sorted out and be removed from the process? Is this possible with a bat file to calculate total size of a group of files with the same name (except for the file type) and remove it, if it is below a specified size?

It could be done, but I would suggest a separate script. Do one thing at a time, do it very well and then move on.

PS. The files get named properly, but a copy operation leaves the original files in place for the next run. Not knowing your operation, this might be a problem with duplicating data.Yes many thanks to you it works, but the problem is that this folder has other files as well and they will also be processed. So my fix was to copy the files I needed to a temporary folder and from there use your script. It seems that I can't add new lines to your script, like:

D:
CD Testfiles
COPY test*.* C:\temp\99\test*.*
C:
CD temp\99
Rename *.TMP *.DAT

Do I need another Bat file for doing this or is it possible to put new lines of codes before and after your script? If that is the case how do I activate another bat file within another?

Thanks


I used the "Call" function and it works. Now I just need to test and change a few settings. Thanks, it was of great help. The file size thing I have to live with for a while, I can remove it manually. Sidewinder, is it possible to change the numerical order so it starts with "0" instead of "1" then I can fix the problem more easily and don't need to remove the files. It now works perfect when I copied the files to a new folder (so I have only those files I need to edit) and run the script from there.

ThanksSoli004,

A couple of thoughts:

Change set /a lines=1 to set /a lines=0 near the top of the script.

You don't need to copy the files to another directory. Try filtering the files returned from the dir command with the same mask you used for your copy instruction:

Code: [Select]for /f "tokens=* delims=." %%v in ('dir /a:-d /b d:\testfiles\test*.*') do (

About sizing the files. You'd need to hold each group in memory until it's determined whether to keep or discard the group. You can use the %%~zv variable within the second for loop for your calculations.

It's not necessary to do all the work from a single script. Simple really is BETTER.

PS. I could swear that set lines=%%j+1 should be replaced by set /a lines=%%j+1, but neither you nor I report an error. Strange.
Sidewinder,
Works as a charm, this is great. removing the files is easier now when they are set to number 0, I can just put a few lines of "Del" and they are gone. All this has made me think of the final goal that I thought was not possible by using batch commands, perhaps I underestimate the potential of using batch

Ok last call, I need to add (create) to each group a txt file that has a few lines of text (same text for every file) ending with ".TAB"
For the moment I have 50 prepared .TAB files in a special folder that I copy to D:/updates in the script so each time I have 50 .TAB files when I perhaps only need let say 10 or less.

This is the text that need to be into each .TAB file for each group. So if there is 10 groups of files it has to be 10 files with this text included (example line1.TAB, line2.TAB etc...).

!table
!version 300
!charset WindowsLatin1

Definition Table
Type NATIVE Charset "WindowsLatin1"
Fields 1
Vagnamn Char (80) ;There were a few ways to approach this. An in-memory array would work, but I chose to create a temporary tab file which could be simply copied and renamed accordingly:

Code: [Select]@echo off
setlocal

> c:\temp\tab.dat echo !table
>> c:\temp\tab.dat echo !version 300
>> c:\temp\tab.dat echo !charset WindowsLatin1
>> c:\temp\tab.dat echo.
>> c:\temp\tab.dat echo Definition Table
>> c:\temp\tab.dat echo Type NATIVE Charset "WindowsLatin1"
>> c:\temp\tab.dat echo Fields 1
>> c:\temp\tab.dat echo Vagnamn Char (80) ;

set /a lines=1

for /f "tokens=1-3 delims=e." %%i In ('dir /o:-n /a:-d /b d:\updates') do (
set /a lines=%%j+1
goto out
)

:out
set /a count=0

for /f "tokens=* delims=." %%v in ('dir /a:-d /b d:\testfiles\test*.*') do (
call :group "%%v"
)
del c:\temp\tab.dat

:group
call set /a count=%%count%%+1
if %count% GTR 4 (
set /a count=1
copy c:\temp\tab.dat d:\updates\line%lines%.tab > nul
call set /a lines=%%lines%%+1
)
for /f "tokens=1-2 delims=." %%w in ("%1") do (
copy d:\testfiles\"%1" d:\updates\line%lines%.%%x > nul
)

Quote
perhaps I underestimate the potential of using batch

Actually many users over estimate the potential of using batch and end up complicating tasks that are better suited to other scripting languages.

Good luck.
Sidewinder,
Thanks but unfortunately its not working completely. The result I get is following for the tab file.

**************************
!version 300
!charset WindowsLatin1

Definition Table
**************************

I can not see why it jumps (not writing) over !table and the last 3 text rows. Is the spaces before the txt (last 3) a problem? I did try to see if that had something to do with it and removed the spaces but that did not work either.

Any clue?I'm not getting your result. In fact I was just congratulating myself on how well this works.

The tab file creation logic at the top of the script requires a single > character in the first line and double >> in all the other lines. Echo itself is transparent enough to accept most characters. Guessing the lines with stars were posted for effect and are not part of the tab file.

To debug, eliminate all the script except the top code where the tab file is created. You should be able to narrow down any error. If you copied/pasted the code, a stray character may have been picked up which is affecting the interpreter. If you retyped the code and you type like me, all bets are off.

Coding is a bore. The real fun comes when you start debugging. Coding is a bore. The real fun comes when you start debugging.

For me good coding is a work of art, I have SEEN just a few lines be making magic.

You are correct again (as usual) something happened when copy and paste, I could not see it but it helped re-typing it THANKS.

The only final "problem" I just find out is that the last "group" does not get a "tab" file.
test_0 to test_19 has a ".tab" but test_20 does not? Can you see this... or have I messed up again?Quote
Can you see this... or have I messed up again?

You didn't mess up, but it does make me wonder how I let this get by. First and last record PROCESSING is usually the most problematic.

Code: [Select]@echo off
setlocal

> c:\temp\tab.dat echo !table
>> c:\temp\tab.dat echo !version 300
>> c:\temp\tab.dat echo !charset WindowsLatin1
>> c:\temp\tab.dat echo.
>> c:\temp\tab.dat echo Definition Table
>> c:\temp\tab.dat echo Type NATIVE Charset "WindowsLatin1"
>> c:\temp\tab.dat echo Fields 1
>> c:\temp\tab.dat echo Vagnamn Char (80) ;

set /a lines=1

for /f "tokens=1-3 delims=e." %%i In ('dir /o:-n /a:-d /b d:\updates') do (
set /a lines=%%j+1
goto out
)

:out
set /a count=0

for /f "tokens=* delims=." %%v in ('dir /a:-d /b d:\testfiles\test*.*') do (
call :group "%%v"
)
del c:\temp\tab.dat

:group
call set /a count=%%count%%+1
if %count% GTR 4 (
set /a count=1
call set /a lines=%%lines%%+1
)
if %count% EQU 4 (
copy c:\temp\tab.dat d:\updates\line%lines%.tab > nul
)
for /f "tokens=1-2 delims=." %%w in ("%1") do (
copy d:\testfiles\"%1" d:\updates\line%lines%.%%x > nul
)

Quote
For me good coding is a work of art

It will be interesting when you revisit this code in the future (and you will) if you see art or just scratch your head in wonderment. Sidewinder,

I just want to thank you for an exellente solution.
Everything is working smoothly with no errors, saving me from lots of copying and renaming files manually.

Salute
5185.

Solve : how i move a file with batch file ??

Answer»

hi
i cant speak English very well , Sorry
plz see this pic :



i added "Move" to my right click ( on exe files ) you can see my way in REGISTRY editor ...
when i click on "Move" test.bat RUN , but i dont know what write script in batch file ??
i want when i click on "Move" the exe file move to for e.g "D:\My Folder"
can u help me ?
thxmove "%1" "D:\my folder"
Quote from: Dias de verano on May 17, 2008, 06:34:35 AM

move "%1" "D:\my folder"
Dias's suggestion should do it for you.

I am curious though.

1. Why do you want to "MOVE" executable files so often that you need it added to the right-click?

2. Are you sure that you want to "MOVE" the executable files?
Or did you mean "COPY" them?

You will NOT be able to use them for their original intended purpose if you "MOVE" them.Quote
move "%1" "D:\my folder"
dont work :-
whats problem ?

hey llmeyer1000
move is e.g
i want for other purpose ...Quote from: Mental on May 17, 2008, 08:21:16 AM
Quote
move "%1" "D:\my folder"
dont work :-
whats problem ?

hey llmeyer1000
move is e.g
i want for other purpose ...

It will work if you do it properly.


Quote from: Mental on May 17, 2008, 08:21:16 AM
hey llmeyer1000
move is e.g
i want for other purpose ...

Please explain "other purpose" and your windows version. I can't imagine any useful purpose for moving executable files. I'm not going to help you screw around with your friends if that is your purpose.

Also, what did not work with Dias's command line? What were the error messages?
We can't figure out what is wrong without information, which you refuse to give.
Answer the questions I posted earlier.Quote
It will work if you do it properly
maybe !

Quote
Please explain "other purpose" and your windows version. I can't imagine any useful purpose for moving executable files. I'm not going to help you screw around with your friends if that is your purpose.
i was writen one app for sony ericsson , in new version i want my app easily for use !! so i decide put one option in right click ...
my app work on THM files but maybe some one dont have this file but all have exe file (for help me) ...
im using sp3

Quote
Also, what did not work with Dias's command line? What were the error messages?
i dont know ! without error massage , just for moment cmd screen open then quicly it closed !!
((sorry for my english))What is in c:\test.bat?
Quote from: Mental on May 17, 2008, 12:57:52 PM
im using sp3
Does that mean Windows XP SP3?
The reason we ask is that certain commands are not available in all versions of Windows, and may also work a bit differently in one version than another.

Quote from: Mental on May 17, 2008, 12:57:52 PM
Quote
Also, what did not work with Dias's command line? What were the error messages?
i dont know ! without error massage , just for moment cmd screen open then quicly it closed !!

Add one or more pauses to your batch file so that you can read the error message before the CMD Window closes. Example:
Code: [Select]@echo off
move "%1" "D:\My Folder"
pause
exit
Have you already created the destination folder?
If not, your code should look more like this:
Code: [Select]@echo off
md "D:\My Folder"
move "%1" "D:\My Folder"
pause
exit

Remove the pause after debugging the batch file.
OK, I tried the code with the pause as I suggested.
You are right. It does not work. ( Sorry Dias )
Plus the error message is rather cryptic.
Quote
The syntax of the command is incorrect.
This is the problem. %1 is already in quotes by default.
You must not add them, or the command will fail with the error above.

The following code does the job with or without the destination folder being present.
Code: [Select]@echo off
if not exist "D:\My Folder" md "D:\My Folder"
move %1 "D:\My Folder"
Thx llmeyer1000 & Dias de verano,
it work for me without " " in the batch file

@Dias
may you test it without " " (in the batch) and tell me your result ?
ThxQuote from: Dias de verano on May 17, 2008, 02:02:17 PM
What is in c:\test.bat?

Dias, a lot is lost to us because of Mental's English. I missed much of what he has meant in several of his posts.(including in this thread.) After reading through the thread several times, I think I finally understand most of it.

Mental,
Is the following explanation of "What I "THINK" you meant" ACCURATE?

"NOTHING" was in Mental's "test.bat" at the start of this thread. He wanted to know how to use the name of the executable file in the batch file "c:\test.bat"

He was trying to show us how he intended to add an action to the right click, and then perform some action on the file. (Moving it was only an example.) If I DECIPHERED it correctly, all he really wanted to know was this.

Quote
How do I use the name of the file I just right-clicked on in the action file "c:\test.bat"?
The answer should have been:
Quote
The filename you just right-clicked on is represented by the environment variable %1 in the action you just called. (In this case it is "c:\test.bat".)
In your batch file:
Use %1 - To expand to the full filename ("drive:\path\filename.ext")(including surrounding quotes.)
Use %~1 - To expand to the full filename (drive:\path\filename.ext)(removing surrounding quotes.)
Use %~n1 - To expand to the filename only
Use %~nx1 - To expand to the filename and extension only
Quote
"NOTHING" was in Mental's "test.bat" at the start of this thread. He wanted to know how to use the name of the executable file in the batch file "c:\test.bat"
yeah exactly
5186.

Solve : I need to check the number of parameters given for batch submit..?

Answer»

Hi All,

I am creating one BATCH file, in that i dont know how many parameters going to be given for me execute, i want to call one external program for each parameter, so i need create one loop for doing this so please help me in this. i ll paste my code below..

--------------------------------------------------------------------------------
@echo off

:: SAS EXE PATH
set saspath="C:\Program Files\SAS\SAS 9.1\sas.exe"

:: OPTIONS FOR RUNNING SAS PROGRAMS
set options=-nosplash -icon

:: STUDY PATH
set stpath=F:\Share\Sudhakar\
%saspath% -sysin %stpath %%1 %options%
%saspath% -sysin %stpath %%2 %options%

-------------------------------------------------------------------------------------------

In this program i am submitting the each parameter to the SAS session in batch mode, is there any WAY to check the number of parameters given and putting that in a loop like .. do i= 1 to (num of parameter) end

Please help in this

thanks

Sudhakar1. There is an error in your code

Code: [Select]%saspath% -sysin %stpath %%1 %options%
%saspath% -sysin %stpath %%2 %options%

Should be...

Code: [Select]%saspath% -sysin %stpath% %1 %options%
%saspath% -sysin %stpath% %2 %options%

2. Make a temp file for the parameter LIST

echo %1 > params.txt
echo %2 >> params.txt

(maximum of 9)

then

read them out in a loop

Code: [Select]
for /f %%I in ("params.txt") do (
%saspath% -sysin %stpath% %%I %options%
)


Thanks you very much but I might be getting hundreds of parameter, so i cant able to write that in the .txt file for passing and moreover how the input(filenames are the input) will be is by selecting the number of fies in the windows explorer and selecting the batch file macro in the right clik menuQuote

In this program i am submitting the each parameter to the SAS session in batch mode, is there any way to check the number of parameters given and putting that in a loop like .. do i= 1 to (num of parameter) end

Nine parameters are addressable, however you can exceed that limit by shifting the parameter list down (right to left). Doing so, moves the tenth parameter into the ninth spot and the first parameter is dropped from the list.

Code: [Select]@echo off
set count=0
:start
if .%1==. goto next
set /a count=%count%+1
shift
goto start
:next
echo %count% arg(s) were passed

The code above is a SNIPPET for counting the parameter list. You MAY find it helpful in your code.

Good luck.



5187.

Solve : to change file name?

Answer»

suppose that i have following file (at leaast 100 files)

01-a.pcl
02-b.pcl
03-c.pcl
04-c.pcl
..........
10-x.pcl

how can i get rid of 01-, 02-,...,10-does the number part have always 2 FIGURES?
vbscript
Code: [Select]SET objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFSO.GetFolder(strFolder)
For Each file In objFolder.Files
If objFSO.GetExtensionName(file) = "pcl" Then
strNewName = Split(file.Name,"-")
file.Name = strNewName(1)
End If
Next

save as script.vbs and on command line ,
Code: [Select]c:\test> CSCRIPT /nologo script.vbs

if you wish for a batch, use a for loop, delim as "-"
Quote from: Dias de verano on May 18, 2008, 11:10:32 AM

does the number part have always 2 figures?


yes

so

is it possible to do by DOS Command is there a possibility to have two files withe diffrunt prefix and same suffix like that

03-c.pcl
04-c.pcl

so that when u delete the prefix from the name u will have two files with the same name in the same directory and have the same ext which is impossible
if no u can use these dos commands

for /f "tokens=1,2 delims=-" %%i in ('dir /b *.pcl') do rename "%%i-%%j" "%%j1"
for /f "tokens=1,2 delims=." %%i in ('dir /b *.pcl1') do rename "%%i.%%j" "%%i.pcl"

u have to rename the file twice to avoid INFINITE loop

5188.

Solve : Running winzip with dos?

Answer»

Does anyone know what the following COMMANDS do?

c:\progra~1\winzip\winzip32 -min -e -j

I know that the path calls the winzip, but I'm not sure about the -min -e and -j.

Thanks in advanceif you navigate to the folder containg the win zip .exe and run "winzip32.exe /?" it will give you a list of switch's.

you should be able to see whats what.

Here are some notes I picked up about the Winzip commandline:


What command line parameters does WinZip support?
Below is some information about the undocumented command line options for using the WinZip program module, winzip32.exe.
WinZip supports command line options to add and extract from files. Be sure to read the Notes section below for additional important information.
Adding Files
The command format is:
winzip32 [-min] action [options] filename[.zip] files
where:
-min specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter.
action
-a for add, -f for freshen, -u for update, and -m for MOVE. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual.
options
-r corresponds to the Include SUBFOLDERS checkbox in the Add dialog and causes WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line.
-ex, -EN, -ef, -es, and -e0 determine the compression method: eXtra, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".
filename.zip
Specifies the name of the Zip file involved. Be sure to use the full filename (including the folder).
files
Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.BAK) are allowed.
Extracting Files
The command format is:
winzip32 -e [options] filename[.zip] folder
where -e is required.
options
-o and -j stand for "Overwrite existing files without prompting" and "Junk pathnames", respectively. Unless -j is specified, folder information is used. Use -sPassword to specify a case-sensitive password. The password can be enclosed in quotes, for example, -s"Secret Password".
filename.zip
Specifies the name of the Zip file involved. Be sure to specify the full filename (including the folder).
folder
Is the name of the folder to which the files are extracted. If the folder does not exist it is created.
Notes
•VERY IMPORTANT: always specify complete filenames, including the full folder name and drive letter, for all file IDs.
•To run WinZip in a minimized inactive icon use the "-min" option. When specified this option must be the first option.
•Only operations involving the built-in zip and unzip are supported.
•Enclose long filenames in quotes.
•When using a list ("@") file, no leading or trailing spaces should appear in file IDs in the list.
•The action and each option must be separated by at least one space.
•WinZip can be used to compress files with cc:Mail . Change the compress= line in the [cc:Mail] section of the appropriate WMAIL.INI files to specify the full path for WinZip followed by "-a %1 @%2". For example, if WinZip is installed in your c:\winzip folder, specify
compress=c:\winzip\winzip.exe -a %1 @%2
Thanks to both of you

5189.

Solve : Breaking FOR Loop?

Answer» HI Again Everyone,

In batch code, is it possible to force a break out of runnng FOR loop ?

I've not been able to figure this out (If it is at all possible)Code: [Select]
@echo off
set MonitorLoops=9
set MonitorInterval=2

for /l %%i in (1,1,%MonitorLoops%) do (
echo Loop %%i of %MonitorLoops% .
ping -n %MonitorInterval% 127.0.0.1 > nul

if %%i EQU 4 exit
)

Any ideas ??

Cheers,
Cameron
Solved ... just needed to use the GOTO statement.
Code: [Select]
@echo off
set MonitorLoops=9
set MonitorInterval=2

for /l %%i in (1,1,%MonitorLoops%) do (
@echo Loop %%i of %MonitorLoops% .
ping -n %MonitorInterval% 127.0.0.1 > nul

if %%i EQU 4 goto :Break1
)
:Break1
@echo End-of-Script.
Why don't you just set MonitorLoops=4 in the first place? Or was that just to demomstrate the question?

Hi Dias,

The eventual code won't be checking MonitorLoop.
It'll be actually checking for the existance of a 'trigger' file.
If it exists, then I need to exit the loop.

The example code (excluding the "if %%i EQU 4 goto :Break1" ) would run for 18 seconds.

Nine(9) loops with two(2) second intervals between loops. This will eventually be set to have an interval of 300 seconds when it goes into production.

Unfortunately I rearely have a chance to create Batch scripts, hence I'm quite rusty. Very grateful for fellas like Sidewinder for their assistance.
I HAPPEN to do more of my scripting on HP-UX systems.

But thanks for the question anyways.

Cheers,
Cameron
That code will ***never*** get to 5
Hi Dias,

Correct - I was deliberately generating a TRUE condition for testing.

Cheers,
Cameron
5190.

Solve : Echo line in next to last line of file?

Answer»

I got an idea last night for a file but they key to it is I need it to echo a line not at the end of the file, but next to last. I can do it that way or i could make it echo say, on line 25 and then move the current line 25 down a line. how do i do either of these?Hey Gamerx, Do you have an example of what you mean?well i didnt want to reveal my idea yet but i guess. I am working on a BATCH AI Interface. What I need it to do is when you ask an unrecognized question it will ask you what you want the response to that question to be, and then it would echo this line inside of a label towards the end:
if %question%=%ASKED% then echo %name%^>%answer%So essentially, you want the batch file to learn 'on the move'sure... if thats what u call it LOL. and also i need to know how to make an IF statement with spaces, if you know how.I'm guessing it is possible but it would be pretty advanced.

I think it can be done with the delete, >> and call commands to constantly create different parts of the batch file...if you UNDERSTAND what I mean...

For example, if you change a setting (or add something), it would delete another batch file and make a new edited on to replace it. Then use the call command to access the batch file.It's a little hard to understand exactly what you want to do. Are you attempting to alter the batch file that is currently running? If so, I don't think that is possible. I think Carbon Dudeoxide is on the right track. But, you do not need to delete the secondary batch file. Simply overwrite it with the redirect > with the first line sent. Then append it with each ADDITIONAL line with >>.

I think you may be able to do what you want by asking you question with set/p in the batch file. Next echo the answer(the variable created with set/p) to a new batch file. Then call the new batch file. When the new batch file is done it will return to the main batch file and finish up. This way the primary batch file is never altered, while the "Answer batch" is created new every time.

The code might look something like this:
Code: [Select].....
line 22
line 23
echo Question: How old are you?
set/p answer=Enter Your Answer Now!
echo @echo off > answer.bat
echo line 2 > > answer.bat
echo %answer% > > answer.bat
echo last line > > answer.bat
call answer.bat
line 25
exit
Is this like those BASIC AI programs that "learned" which we all typed in to our C64s in the 1980s? You know...

Are you thinking of an animal?
Yes
is it a cat?
no
what is it?
a dog
how can i tell a dog from a cat
a dog barks

etc etc

5191.

Solve : How much should a DOS partition be??

Answer»

Hi,

How much Megs should a DOS partition should be or what does everyone has?Keep it small if all you are doing is learning, maybe 5 % -10 % of you HD. 20 MB used to be considered a large HD. If you made it the smallest available partition size it would probably be way more than that.

You won't be able to repartition without losing data, UNLESS you have Partition Magic or something similar. The Windows/DOS Fdisk method will destroy all your current data. Be careful!Quote from: llmeyer1000 on May 29, 2008, 03:56:48 PM

Keep it small if all you are doing is learning, maybe 5 % -10 % of you HD. 20 MB used to be considered a large HD. If you made it the smallest available partition size it would probably be way more than that.

You won't be able to repartition without losing data, unless you have Partition Magic or something similar. The Windows/DOS Fdisk method will destroy all your current data. Be careful!

The PART of it is, when it comes to basic DOS commands. I don't KNOW crap. When it comes to format C: /s. I understand. When it comes to Killdisk, I understand. How much Megs is 5%? Such as is it 2000 or 3000 or etc?Quote from: php111 on May 29, 2008, 04:03:35 PM
How much Megs is 5%? Such as is it 2000 or 3000 or etc?

It is 5% of your disk size. Or 1/20 of your disk size. (Whatever that is.)

You know your disk size.

We don't know your disk size.

Quote from: php111 on May 29, 2008, 04:03:35 PM
How much Megs is 5%? Such as is it 2000 or 3000 or etc?

How large is the HD you are using?
If it is say 40 GB, then 5% is 2GB. (40 x .05 = 2)

In an earlier post you mentioned that you were TRYING to learn DOS 6.22.

Quote
I have a dual boot setup with XP Pro and MS-DOS v6.22. How can I learn some or all things about DOS such as my commands and so on?

2 GB is huge in DOS 6.22 world. And now that I remember, 2GB is also the maximum size allowable for a FAT(16) partition for DOS.

What partitioning software are you going to use?

Look on the site BC_Programmer told you about in an earlier post.

www.vetusware.com

Utilities section:
Partition Magic 4

It's an older version, but may still be adequate for you. (Maybe not, depending the HD size and type of partitions already installed.)
5192.

Solve : creating a batch file to merge two files into one?

Answer» HI,
I want to create a batch file that will merge two files, LET's CALL them data_1.txt and data_2.txt into one single data.txt file. I'm lacking slightly in my knowledge of commands so if someone could point me in the right direction that would be GREAT!
THANKS in advancecopy data_1.txt+data_2.txt data_3.txtPerfect! Thank you
5193.

Solve : Could not run batch file by double-click?

Answer»

I am using Windows Server 2003.

My problem is that after creating the batch file with .bat extension, when i try to run it by doulbe clicking it, then it is opened in Notepad instead of exececution.

Moreover, the icon of the batch file is ALSO of Notepad.

If you created it in notepad, very likely it has a .txt extension

Check your explorer view and ensure that 'Hide extensions for known file types' is unchecked

GrahamOr just open the file with Notepad and go to File --> Save As --> file.batThanks for the reply.

I have made sure that extension of these files is bat.

These files run successfully when i run them from command prompt but could not run by mouse double click.

I REMEMBER, once i tried to add bat extension in the folder OPTIONS box at Tools->Folder Options to open these in Notepad which i removed after that.

From that time, i am getting this problem.
Try this from a command prompt
ASSOC .bat
will show you what is associated with .bat files
ASSOC .bat=

should remove the association if it isnt what you want

not too sure if that will RESTORE the NORMAL operation or not

Graham
Right click any batch file in Explorer. Choose "open with...", select cmd.exe, and check "always use for files of this type".
DOH!
even easier
GI can't do that here. When I right click a Batch File, it doesn't give ma an 'Open With' option...

Edit: Wait, This is Windows XP and he is using Windows 2003 Server. Might be different, I don't know.Thanks for all that help.

My problem is solved when i executed the following command on the command prompt

ASSOC .bat=batfile

Excellent !
my post wasnt wasted after all
Graham

5194.

Solve : Writing the results of a DOS program to a file?

Answer»

macdad, I don't think you understand what oba is TRYING to do.yes i dont know wat oba wants accomplished here

Code: [Select]for /f "tokens=* delims=" %%i in ('DIR /o:-d /s /b F:\sqldata\MSSQL\BACKUP\master\*.BAK') do (
copy %%i "\\C:\master"
goto endmstr1
)
:endmstr1

for /f "tokens=* delims=" %%i in ('dir /o:d /s /b Z:\master\*.*') do (
del %%i
goto endmstr2
)
:endmstr2Quote from: macdad- on May 16, 2008, 02:17:25 PM

yes i dont know wat oba wants accomplished here

In this code, he is looking into the folder F:\sqldata\MSSQL\BACKUP\master\ and all of its subfolders, and copying any .BAK file that may be there to the folder C:\master.

He is making dir SORT its output in reverse date order, why, I do not know.

Code: [Select]for /f "tokens=* delims=" %%i in ('dir /o:-d /s /b F:\sqldata\MSSQL\BACKUP\master\*.BAK') do (
copy %%i "\\C:\master"
goto endmstr1
)
:endmstr1

Here, he is deleting every file in every subdirectory below the directory Z:\master\. This time the dir output is sorted in date order, again, I do not know why.

Code: [Select]for /f "tokens=* delims=" %%i in ('dir /o:d /s /b Z:\master\*.*') do (
del %%i
goto endmstr2
)
:endmstr2
His eccentric use of labels is intriguing.

These 2 pieces are exactly EQUIVALENT to the above quoted code sections.

Code: [Select]for /f "tokens=* delims=" %%i in ('dir /o:-d /s /b F:\sqldata\MSSQL\BACKUP\master\*.BAK') do copy %%i "\\C:\master"
Code: [Select]for /f "tokens=* delims=" %%i in ('dir /o:d /s /b Z:\master\*.*') do del %%ithanks Dias, i always get lost in the For commandsThanks for all the input. I have the log I want now. I simple run a batch file that echoes the FIRST batch file's input to a log file.


5195.

Solve : Supress copy output in Batch file?

Answer»

Hi,

When i GIVE a copy COMMAND in BATCH file, the output is:
1 file(s) copied.

How can i suppress this thing?

ThanksCopy path\source.ext path\destination.ext > nulHow did i miss that

Thanks Found BLACKOUT util on EASY2TOUCH computer from restaurant.?Ignore the foolish SPAMMER, vibhor.

5196.

Solve : question about setting days to vars?

Answer»

Is it possable under xp to give give a user a prompt or window to allow them to select from a list of days.

:example

SET Choice=
echo TYPE the day you wish for this to run and press Enter:
echo Example: M, T, W, TH, F
SET /P Choice=day:

The issue I am having is getting this code to work. I have tried several diffrent options but none work the way I want them to.

I will be using this input from the user to make a scheduled task that will run under xp. If any one can come up with a way to do this it would be greatly appreciated.How about this code?

Code: [Select]@ech off
echo Type the day you wish for this to run and press Enter:
echo Example: M, T, W, TH, F
set /p choice=Day:
if /i %choice%==M goto :M
if /i %choice%==T goto :T
if /i %choice%==W goto :W
if /i %choice%==TH goto :TH
if /i %choice%==F goto :F
exit
:M
do stuff
pause
exit
:T
do stuff
pause
exit
ect....yes that will work but I also need this to allow the user to select more then one day possably all the days, Monday through Friday, then set these to a varable in the form of:

M, T, W, TH, F

thanks,
WayneI think it would be possible it more of the IF command but I think there is another way.
Sit tight and someone may point you in the right direction.


Code: [Select]if /i %choice%==M goto :M
if /i %choice%==T goto :T
if /i %choice%==MT goto :MT
That may get a little COMPLEX though...you might want to give them a menu instead
eg
Code: [Select]1) Monday
2) Tuesday
and so on
They can only enter 1, 2 .....Quote from: ghostdog74 on May 19, 2008, 10:11:05 PM

you might want to give them a menu instead
eg
Code: [Select]1) Monday
2) Tuesday
and so on
They can only enter 1, 2 .....

yes I have got that but I wish to allow them to select any of the days they wish

:example:
Mondays Wednesdays and Fridays.

I can not get this to work in a batch. I was hopefull that someone has done this in the past or knows of a way to allow user choice for more then one option at a time.why don't you ask for a yes/no answer for each day in turn?
Quote from: DIAS de verano on May 20, 2008, 08:08:50 AM
why don't you ask for a yes/no answer for each day in turn?


This is still not working for me. Here is a section of the code that keeps giving me problems.

Code: [Select]:LOOPZB
CLS

SET Choice=
ECHO Do you want JK Defrag to run on Monday?
ECHO Enter Yes or No
SET /P Choice=Monday:


ECHO %choice% |findstr /i /r "[n]" > NUL
IF /I %errorlevel% EQU 0 SET mon=no && GOTO LoopZC
ECHO %choice% |findstr /i /r "[y]" > NUL
IF /I %errorlevel% EQU 0 SET mon=yes && GOTO LoopZC

ECHO %choice% is not a valid choice
ECHO please try agin
ping -n 2 localhost > nul
GOTO LoopZB

:LoopZC
CLS

SET Choice=
ECHO Do you want JK Defrag to run on Tuesday?
ECHO Enter Yes or No
SET /P Choice=Tuesday:

ECHO %choice% |findstr /i /r "[n]" > NUL
IF /I %errorlevel% EQU 0 SET tues=no && GOTO LoopZD
ECHO %choice% |findstr /i /r "[y]" > NUL
IF /I %errorlevel% EQU 0 SET tues=yes && GOTO LoopZD


ECHO %choice% is not a valid choice
ECHO please try agin
ping -n 2 localhost > nul
GOTO LoopZC

:LoopZD
CLS

SET Choice=
ECHO Do you want JK Defrag to run on Wednesday?
ECHO Enter Yes or No
SET /P Choice=Wednesday:


ECHO %choice% |findstr /i /r "[n]" > NUL
IF /I %errorlevel% EQU 0 SET wed=no && GOTO LoopZE
ECHO %choice% |findstr /i /r "[y]" > NUL
IF /I %errorlevel% EQU 0 SET Wed=yes && GOTO LoopZE

ECHO %choice% is not a valid choice
ECHO please try agin
ping -n 2 localhost > nul
GOTO LoopZD

:LoopZE
CLS

SET Choice=
ECHO Do you want JK Defrag to run on Thursday?
ECHO Enter Yes or No
SET /P Choice=Thursday:

ECHO %choice% |findstr /i /r "[n]" > NUL
IF /I %errorlevel% EQU 0 SET thurs=no && GOTO LoopZF
ECHO %choice% |findstr /i /r "[y]" > NUL
IF /I %errorlevel% EQU 0 SET thurs=yes && GOTO LoopZF

ECHO %choice% is not a valid choice
ECHO please try agin
ping -n 2 localhost > nul
GOTO LoopZE

:LoopZF
CLS

SET Choice=
ECHO Do you want JK Defrag to run on Friday?
ECHO Enter Yes or No
SET /P Choice=Friday:

ECHO %choice% |findstr /i /r "[n]" > NUL
IF /I %errorlevel% EQU 0 SET FRI=no && GOTO LoopZG
ECHO %choice% |findstr /i /r "[y]" > NUL
IF /I %errorlevel% EQU 0 SET fri=yes && GOTO LoopZG

ECHO %choice% is not a valid choice
ECHO please try agin
ping -n 2 localhost > nul
GOTO LoopZF

:LoopZG
ECHO you choose to run on:
ECHO you choose to run on: >> "\\%computername%\C$\%homepath%\desktop\defrag.log"
IF %mon% == yes ECHO Monday && SET day1=M
IF %mon% == yes ECHO Monday >> "\\%computername%\C$\%homepath%\desktop\defrag.log"
IF %tues% == yes ECHO Tuesday && SET day2=T
IF %tues% == yes ECHO Tuesday >> "\\%computername%\C$\%homepath%\desktop\defrag.log"
IF %wed% == yes ECHO Wednesday && SET day3=W
IF %wed% == yes ECHO Wednesday >> "\\%computername%\C$\%homepath%\desktop\defrag.log"
IF %thurs% == yes ECHO Thursday && SET day4=TH
IF %thurs% == yes ECHO Thursday >> "\\%computername%\C$\%homepath%\desktop\defrag.log"
IF %fri% == yes ECHO Friday && SET day5=F
IF %fri% == yes ECHO Friday >> "\\%computername%\C$\%homepath%\desktop\defrag.log"
Pause

IF '%day1%' =='' (SET day2=T) ELSE IF NOT '%day2%' =='' SET day2=,T
IF '%day1%' =='' && IF '%day2%' =='' (SET day3=W) ELSE IF NOT '%day3%' =='' SET day3=,W
IF '%day1%' =='' && IF '%day2%' =='' && IF '%day3%' =='' (SET day4=TH) ELSE IF NOT '%day4%' =='' SET day4=,TH
IF '%day1%' =='' && IF '%day2%' =='' && IF '%day3%' =='' && IF '%day4%' =='' (SET day5=F) ELSE IF NOT '%day5%' =='' SET day5=,F

set day=%day1%%day2%%day3%%day4%%day5%
Pause

The batch fails just before the first pause if you do not choose yes to the Monday prompt.

thanks again,
WayneThat code looks way too complex and ambitious. Get the functioning right first and then add the error trapping.

Code: [Select]
@echo off

:start

REM get user input

echo.
set /p mon="Monday y/n ?"
set /p tue="Tuesday y/n ?"
set /p wed="Wednesday y/n ?
set /p thu="Thursday y/n ?"
set /p fri="Friday y/n ?"

REM set up string with spaces between letters
set string=
if "%mon%"=="y" set string=M
if "%tue%"=="y" set string=%string% T
if "%wed%"=="y" set string=%string% W
if "%thu%"=="y" set string=%string% TH
if "%fri%"=="y" set string=%string% F

REM remove any leading space
if "%string:~0,1%"==" " set string=%string:~1,255%

REM change each space to a comma and a space
set string=%string: =, %

echo.
echo You chose these days %string%

echo.
set /p ok="Is this OK y/n ?"

if "%ok%"=="n" goto start
5197.

Solve : Newbie help: bat calling .bat file only executes 1st file?

Answer»

This should be easy...

I'm trying to execute 28 .bat files, located on c:\dir\subdir\
[1.BAT, 2.BAT, 3.BAT... 28.BAT]

the 'CONTROL.bat' file lives on e:\myholddir


CONTROL.BAT
C:
CD\DIR\SUBDIR
1.BAT
REM --- 1
2.BAT
REM --- 2
3.BAT
REM --- 3
...
...
28.BAT
REM --- EOF ---


(I execute (from command prompt, win200),
the 1.bat executes successfuly, but ends.

2.bat and the rem --- 1 never is called.

should I add 'CALL' in front of the *.bat files?

fwiw, the 1.bat is calling a 3rd party tool (data integrator).

any ideas?

thanks in advance!!! Do any of the 1.BAT, 2.BAT etc have an EXIT in them?

this will cause the whole thing to stop running.Quote

bat calling .bat file only executes 1st file

The problem is you're not calling the batch files but EXECUTING them. There is a subtle difference. When you call a batch file a mechanism is setup to return to the calling file. A called file can in turn call another file, but eventually the run unit will climb the return stack back to the original caller. The way you setup your run unit is to execute another file with no hope of ever returning.

As previously mentioned an exit statement in any of the called files will prematurely end the entire run unit.

Code: [Select]C:
CD\DIR\SUBDIR
call 1.BAT
REM --- 1
call 2.BAT
REM --- 2
call 3.BAT
REM --- 3
...
...
call 28.BAT
REM --- EOF ---

Hope this helps. THANKS FOR THE REPLIES!!!
more info:


the 1.bat file contents:

C:\DATAIN~1/bin/AL_RWJ~1.EXE "C:\DataIntegrator/log/justice_server/" -w "INET:URANUS:3511" -C "C:\DataIntegrator/log/JOB_CMT_Act_Remark.txt"

(no exit listed...)

I tried adding CALL in front of 1.bat (CALL 1.bat), and that allowed job 2 to start...

now it appears hung...

(which is possible as the Data Integrator product is close on ram)




the REAL gory detials: [JOB_CMT_translate.bat = 1.bat (in my example)]



REM *** batch job to execute a bulk load ***
REM mrbill 5/29/08 (run)
REM job order matters!!!
REM -----------------------------------------
C:
CD\DataIntegrator\Log
rem ----------------- start ----
call JOB_CMT_translate.bat
rem ----------------- 1 ----
call JOB_CMT_defendant.bat
rem ----------------- 2 ----
call JOB_CMT_Collection.bat
rem ----------------- 3 ----
call JOB_CMT_Count.bat
rem ----------------- 4 ----
call JOB_CMT_Remarks.bat
rem ----------------- 5 ----
call JOB_CMT_Def_Desc.bat
rem ----------------- 6 ----
call JOB_CMT_Activity.bat
rem ----------------- 7 ----
call JOB_CMT_Act_Remark.bat
rem ----------------- 8 ----
call JOB_CMT_Sentence.bat
rem ----------------- 9 ----
call JOB_CMT_Bond.bat
rem ----------------- 10 ----
call JOB_CMT_Bond_Remark.bat
rem ----------------- 11 ----
call JOB_CMT_Sentence_Prov.bat
rem ----------------- 12 ----
call JOB_CMT_Witness.bat
rem ----------------- 13 ----
call JOB_CMT_Related_Case.bat
rem ----------------- 14 ----
call JOB_CMT_Appeal.bat
rem ----------------- 15 ----
call JOB_CMT_App_Remark.bat
rem ----------------- 16 ----
call JOB_CMT_Arrest.bat
rem ----------------- 17 ----
call JOB_CMT_Attorney.bat
rem ----------------- 18 ----
call JOB_CMT_Sc_Event.bat
rem ----------------- 19 ----
call JOB_CMT_Add_Sch_Cnts.bat
rem ----------------- 20 ----
call JOB_CMT_Remark_Note.bat
rem ----------------- 21 ----
call JOB_CMT_Add_Remark.bat
rem ----------------- 22 ----
call JOB_CMT_Def_Note.bat
rem ----------------- 23 ----
call JOB_CMT_Evidence.bat
rem ----------------- 24 ----
call JOB_CMT_Alias.bat
rem ----------------- 25 ----
call JOB_CMT_Custody.bat
rem ----------------- 26 ----
call JOB_CMT_Sheriff_Note.bat
rem ----------------- 27 ----
call JOB_CMT_Warrant.bat
rem ----------------- 28 ----

REM ))))))))) all done )))))))))))))))))

rem *********************** end of job *******
Quote
I tried adding CALL in front of 1.bat (CALL 1.bat), and that allowed job 2 to start...

now it appears hung...

The calls are appropriate. The sequence of events so far would be, control.bat starts which in turn calls 1.bat which executes C:\DATAIN~1/bin/AL_RWJ~1.EXE. When the latter is finished, control reverts back to 1.bat which has no more instructions, so control reverts back up the chain to control.bat which then calls 2.bat.

The numbered (1.bat, 2.bat, etc) batch files do not terminate until the exe file being executed is ended. My guess is that the DataIntegrator program is the source of the hangup.

Batch files are containers for instructions you can duplicate at the command prompt. Try entering the control.bat commands MANUALLY at the prompt and see how things go. Liberal use of echo on is recommended until you get the run unit working.

Any reason you need all these batch files? Could you run the RJW programs directly from control.bat?

Hope this helps.

5198.

Solve : Using if else in batch scripting?

Answer»

How to check 3 conditions from batch scripting

ex:-

if (condition1) & (condition2) are true do this

else do this
How about nesting ifs? Something LIKE:

Code: [Select]IF condition1 (
IF condition2 command
) ELSE command

Two-Eyes %It depends. Are the three tests know to be valid tests? That is, do we already know that the test will give a True or False without raising an error.

Nested IF statements are a good idea to prevent an invalid test problem. An example of this is when you need to test for the presence of a file and if true USE the file in some further test.You can do simple if - else tests in batch; there is no THEN keyword. You KEEP the IF code and the ELSE code apart with parentheses. Remember that (a) the closing parenthesis of the code block to be executed if the initial IF test is passed, (b) the ELSE keyword, (c) the opening parenthesis of the code block to be executed if the ELSE is triggered, MUST ALL BE ON THE SAME LINE.

Code: [Select]IF "%animal%"=="dog" (
echo canine
echo likes bones
) ELSE (
echo not canine
echo might not like bones
)
..To do Boolean tests you have to do a bit of trickery

Condition 1: animal is dog
Condition 2: COLOUR is red

Code: [Select]REM AND
set bool=0
IF "%animal%"=="dog" set /a bool=%bool%+1
IF "%colour%"=="red" set /a bool=%bool%+1
if %bool% EQU 2 (
echo condition 1 AND condition 2 are both true
) ELSE (
echo condition 1 AND condition 2 are NOT both true
)

REM OR
set bool=0
IF "%animal%"=="dog" set /a bool=%bool%+1
IF "%colour%"=="red" set /a bool=%bool%+1
if %bool% GEQ 1 (
echo Either condition 1 OR condition 2 is true
) ELSE (
Neither condition 1 nor condition 2 is true
)

To avoid spoiling all your fun, I'll leave you to figure out NOT using this approach...Did you leave out an echo?
Here is XOR
Code: [Select]if %bool% EQU 1 (
echo condition 1 XOR condition 2 is true
) ELSE (
echo condition 1 XOR condition 2 is false
)Which is what people think OR means!Quote from: Geek-9pm on September 16, 2009, 02:44:47 PM

Did you leave out an echo?

Yup

Exclusive OR Venn diagram: the red part is true


XOR is one or the other but not both.

A XOR B = (NOT (A=B) and (A OR B))Quote
Care should be taken when converting an English sentence into a formal Boolean statement. Many English sentences have imprecise meanings, e.g. "All that glisters is not gold,"[1] which could mean that "NOTHING that glisters is gold" or "some things which glister are not gold".

AND and OR can also be used interchangeably in English, in certain cases:

* "I always carry an umbrella for when it rains and snows."

* "I always carry an umbrella for when it rains or snows."

* " I never walk in the rain or snow."

http://en.wikipedia.org/wiki/Boolean_logic

"I always carry an umbrella for when it rains and snows."

this is valid because there is an implication:

"I always carry an umbrella for when it rains and for when it snows."Quote from: BC_Programmer on September 16, 2009, 08:52:43 PM
"I always carry an umbrella for when it rains and snows."

this is valid because there is an implication:

"I always carry an umbrella for when it rains and for when it snows."
OK, Maybe we can close this thread if you will just write a batch file using the IF...ELSE structure to demonstrate the above logic.
Thanks Salmon Trout
-----
IF "%animal%"=="dog" set /a bool=%bool%+1
IF "%colour%"=="red" set /a bool=%bool%+1
if %bool% EQU 2 (
echo condition 1 AND condition 2 are both true
) ELSE (
echo condition 1 AND condition 2 are NOT both true
)
---------
This thing is really working great, now i can allow any no. of conditions in a IF loop.
initially i thought like "C" language i can enter elseif condition.
Thanks again.
5199.

Solve : Help with batch file- read Nth line in delimited text file?

Answer»

Ghost Dog wrote:

<<"A quiz for you....tell me if the code below is a batch file....

Code:
@echo off
setLocal EnableDelayedExpansion
cscript /nologo myscript.vbs > newfile
mv newfile original file
for /F %%a in ('type file') do (echo %%a)


The above, contains a series of commands as defined by your definition.... ">>

Gosh, GhostDog is really smart. Now GhostDog will demostrate that the *.vbs script fits the defintion of a Batch File.

That is great GhostDog. KEEP posting your VBS script and other code.

But please, GhostDog, post your test data and that your *.vbs( VBScript ) script actually WORKS. Well, you guys seem to have scared off the OP, who wrote:

Quote

I have to write a batch file in DOS for work

vbscript is probably disabled...

Quote from: billrich on September 13, 2009, 01:35:01 AM
Gosh, GhostDog is really smart.
that sounds sarcastic...but nevertheless...thank you for your compliment.

Quote
Now GhostDog will demostrate that the *.vbs script fits the defintion of a Batch File.
its already done. like that i posted.

Quote
But please, GhostDog, post your test data and that your *.vbs( VBScript ) script actually works. [/font]

since you are so insistent
Code: [Select]C:\test>more file
1,0,mess,nothing
2,0,mess,nothing
3,0,mess,nothing
4,0,mess,nothing
5,1,mess,nothing

C:\test>cscript /nologo test.vbs
1,0,mess,nothing
2,0,mess,nothing
3,new value,mess,nothing
4,0,mess,nothing
5,1,mess,nothing

C:\test>more test.vbs
Set objFS=CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfLine
linenumber = objFile.Line
strLine = objFile.ReadLine
If linenumber = 3 Then
csv = Split(strLine,",")
csv(1) = "new value"
strLine = Join(csv,",")
End If
WScript.Echo strLine
Loop
objFile.Close


2nd field, line 3 is changed to "new value". does that answer your query?Quote
GhostDog wrote:

"2nd field, line 3 is changed to "new value". does that answer your query?"

No, the second field is a flag field and must be either 1 or 0. "new value" is the WRONG answer. Your code does not work.

You also did not assign the the first field to a variable.

Why post code that has not been tested?

The OP requested real "Batch code" not incorrect VBScript.Quote from: billrich on September 13, 2009, 10:46:40 AM
Your code does not work.
yes it does work. Except that I did not provide OP with FULL code. Implementing that flagging system is fairly easy.
I want OP to try himself.
Code: [Select]if csv(1) = 0 Then
csv(1) = 1
end if
in fact, there is really no need to do the above, because by changing "new value" in my code to "1", it will still do the same thing...

Quote from: billrich
You also did not assign the the first field to a variable.
if OP has the motivation to learn vbscript, he should be able to do that himself.

Quote
Why post code that has not been tested?
its tested .... you just don't see the point i am making...

Quote
The OP requested real "Batch code" not incorrect VBScript.
once again, define what is real Batch code, accurately.

Dude, if you are GOING to provide him your solutions in full , go ahead. Depending on my MOOD, I am not obliged to solve everything for OP.

If i really want to nitpick about your code, i would do that, but i will not. for example, Input argument checking, input file format ambiguity, eg your code checks for ",0," .... what if the input data is " , 0 ,"
therefore, would you just give it a rest...

5200.

Solve : Help Creating a Batch File to Set Clock Back 5 minutes?

Answer»

Quote from: PATIO on September 13, 2009, 07:38:30 PM

That's NOT what Salmon was saying...re-read the Post.
I STAND CORRECTED. He did not say what I thought he SAID.