

InterviewSolution
Saved Bookmarks
1. |
Solve : How to capture batch commands? |
Answer» <html><body><p>I have a batch file which performs some commands, how can i capture all the commands its performing in to a text file. Any help is highly <a href="https://interviewquestions.tuteehub.com/tag/appreciated-2438458" style="font-weight:bold;" target="_blank" title="Click to know more about APPRECIATED">APPRECIATED</a><br/>C:test>type capture.bat<br/>echo off<br/>date /t > capture.txt<br/>time /t >> capture.txt<br/><br/>help >> capture.txt<br/>echo.<br/><br/>echo type capture.txt<br/>type capture.txt | more<br/><br/>Output:<br/>C:test>capture.bat<br/><br/><br/>type capture.txt<br/>Wed 08/11/2010<br/>03:38 PM<br/>For more information on a specific command, type HELP command-name<br/>ASSOC Displays or modifies file extension associations.<br/>ATTRIB Displays or changes file attributes.<br/>BREAK Sets or clears extended CTRL+C checking.<br/>BCDEDIT Sets properties in boot database to control boot loading.<br/>CACLS Displays or modifies access control lists (ACLs) of files.<br/>CALL Calls one batch program from another.<br/>CD Displays the name of or changes the current directory.<br/>CHCP Displays or sets the active code page number.<br/>CHDIR Displays the name of or changes the current directory.<br/>CHKDSK Checks a disk and displays a status report.<br/>CHKNTFS Displays or modifies the checking of disk at boot time.<br/>CLS Clears the screen.<br/>CMD Starts a new instance of the Windows command interpreter.<br/>COLOR Sets the default console foreground and background colors.<br/>COMP Compares the contents of two files or sets of files.<br/>COMPACT Displays or alters the compression of files on NTFS partitions.<br/>CONVERT Converts FAT volumes to NTFS. You cannot convert the<br/> current drive.<br/>COPY Copies one or more files to another location.<br/>DATE Displays or sets the date.<br/>DEL Deletes one or more files.<br/><strong>OR</strong> you can do it the easy way and use redirection on the command line when you launch the file:<br/><br/> Code: <a>[Select]</a>batfile.bat > capture.txt<br/><br/>batfile.bat >> capture.txt<br/><br/>Using a single redirection symbol will create a new file or overwrite an existing file.<br/>Using a double redirection symbol will create a new file if it does not exist or append to an existing file.<br/><br/><strong>FYI:</strong> If the batch file contains prompt(s), they will be unseen by the user but there will still be a wait for input on the console. This may lead to laughable unpredictable results.<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/good-1009017" style="font-weight:bold;" target="_blank" title="Click to know more about GOOD">GOOD</a> luck. Thank you sidewinder and victoria for both of your replies.<br/><br/>I used the single pipe batfile > capture.txt<br/><br/>However something strange is happening here. I am executing ftp commands in my bat file. the last but one is the <a href="https://interviewquestions.tuteehub.com/tag/supposed-1235466" style="font-weight:bold;" target="_blank" title="Click to know more about SUPPOSED">SUPPOSED</a> to download a file. Now when I run the bat file directly i see something like this<br/><br/>ftp> 20mb file transferred in 20.68 seconds 876.877kbytes/sec<br/>ftp> quit<br/><br/>but when the output is written in to the text file i see<br/><br/>ftp> 20mb file transferred in seconds kbytes/sec<br/>ftp> 20.68876.877 quit<br/><br/>Both the seconds and kbps are written on the quit command line. Which i dont understand why. Any input is highly appreciated.<br/>Not really sure, but the FTP command places you in another environment. I'm surprised you <a href="https://interviewquestions.tuteehub.com/tag/got-23540" style="font-weight:bold;" target="_blank" title="Click to know more about GOT">GOT</a> any output from the FTP commands. In any case it seems like the carriage return/line feed characters are not being written properly which may have to do with the media (console vs. disk)<br/><br/>Try redirecting the FTP command output from within the batch file in addition to the redirection at the command line. Sometimes you just have to tweak the code until it works. <br/><br/>Good luck. Quote from: dmog on August 11, 2010, 03:26:05 PM</p><blockquote>I used the single redirect batfile > capture.txt<br/><br/>ftp> 20mb file transferred in seconds kbytes/sec<br/>ftp> 20.68876.877 quit<br/><br/>Both the seconds and kbps are written on the quit command line. Which i dont understand why. Any input is highly appreciated.<br/><br/></blockquote> <br/>ftp> transfer <br/>ftp>echo.<br/><br/><br/>ftp>echo quit<br/><br/>Rem Between the command that does the transfer and the command to quit<br/><br/>Rem Use echo. echo. places a blank line<br/><br/>( also a redirect > of each command <a href="https://interviewquestions.tuteehub.com/tag/might-560522" style="font-weight:bold;" target="_blank" title="Click to know more about MIGHT">MIGHT</a> fix the problem. )<br/><br/>p.s. a pipe | and a redirect >> are two different procedures. A pipe | sends<br/>the output to another program as the input. Redirect >> goes to a text file.</body></html> | |