Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Solved: Batch File Explanation

Reply  
Thread Tools
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
25-Jan-2010, 10:41 AM #1
Question Solved: Batch File Explanation
I have a batch file that runs the following code:

Code:
echo y|chkdsk c: /f/r
Could someone please explain this code? How does the code know to answer the question with "yes"?
leroys1000's Avatar
Distinguished Member with 5,560 posts.
 
Join Date: Aug 2007
Location: Boise,Idaho
Experience: Intermediate
25-Jan-2010, 11:21 AM #2
y=yes.
| pipe to run checkdisk on disk c:
/f=fix
/r=repair
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
25-Jan-2010, 12:02 PM #3
I understand all of that, but why does the y come before the chkdsk command? I would have thought that the y would come after.
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
25-Jan-2010, 04:08 PM #4
Do you see a Y option in the chkdsk help.
Code:
C:\Users\Squashman>chkdsk /?
Checks a disk and displays a status report.


CHKDSK [volume[[path]filename]]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:size]] [/B]


  volume          Specifies the drive letter (followed by a colon),
                  mount point, or volume name.
  filename        FAT/FAT32 only: Specifies the files to check for fragmentation
.
  /F              Fixes errors on the disk.
  /V              On FAT/FAT32: Displays the full path and name of every file
                  on the disk.
                  On NTFS: Displays cleanup messages if any.
  /R              Locates bad sectors and recovers readable information
                  (implies /F).
  /L:size         NTFS only:  Changes the log file size to the specified number
                  of kilobytes.  If size is not specified, displays current
                  size.
  /X              Forces the volume to dismount first if necessary.
                  All opened handles to the volume would then be invalid
                  (implies /F).
  /I              NTFS only: Performs a less vigorous check of index entries.
  /C              NTFS only: Skips checking of cycles within the folder
                  structure.
  /B              NTFS only: Re-evaluates bad clusters on the volume
                  (implies /R)

The /I or /C switch reduces the amount of time required to run Chkdsk by
skipping certain checks of the volume.

C:\Users\Squashman>
You need to answer the question that comes back from chkdsk so that it can run unatteneded.
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
25-Jan-2010, 04:20 PM #5
So, the
Code:
 y|
is answering the question produced by the code that follows?

Only options/switches go after the command?
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
25-Jan-2010, 05:54 PM #6
run the chkdsk code by itself. What does it do? What does it ask you to do?
Posted via Mobile Device
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
26-Jan-2010, 08:59 AM #7
When I run the chkdsk command it indicates that the active drive cannot be locked, and therefore cannot run. It then ask if the chkdsk command can run the next time the computer is restarted.

A y or n must be entered to answer the question.


I guess my overall goal is to learn why the y| goes before the code and not after. How does the code know the y is meant to answer the question of the chkdsk code if it is done before the questions is ever asked?
__________________
Computerman29642
"Why so serious?....let's put a smile on that face" - The Joker
devil_himself's Avatar
Distinguished Member with 4,922 posts.
 
Join Date: Apr 2007
Location: India
Experience: Advanced
26-Jan-2010, 10:42 AM #8
Every program has three open "File Handles" by default [stdin -> #0 connected to keyboard, stdout -> #1 | stderr -> #2 connected to terminal | display]

when chkdsk asks a question it does so by printing it on the stdout and waiting for an answer on the stdin
the pipe ( | ) connects the stdout of one program to the stdin of another ex -
command 1 | command 2 -> this connects the stdout of command 1 to the stdin of command 2

echo y|chkdsk c: /f/r
so the stdout of echo [ echo y ] which is connected to the stdin of chkdsk is used to fulfill the request of yes or no
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
26-Jan-2010, 10:51 AM #9
Thank you. The explanation helps very much.

I will read the information provided in the link.
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
26-Jan-2010, 10:52 AM #10
Thank you Squashman and devil_himself for all the reponses. You both have helped to clear up my confusions. I really appreciate the help from both of you.
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
26-Jan-2010, 11:41 AM #11
Most cmd line utilities have the ability to take input from a previous cmd as explained above. So you just use the pipe to pass the output of the previous cmd for the input to the next cmd.

some examples.
find all files that don't have the file extension ZIP, PGP or XLS.
Code:
Dir /a-d /-c /q /O-S^|Findstr /I /V /E ".zip .pgp .xls
This is how I time stamp my log files.
Code:
Echo exit|cmd /q /k prompt $D $T>>somelogfile.txt
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:53 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.