xtremee Posted November 12, 2014 Share Posted November 12, 2014 Hi guys it is me again, I bet you missed me I would like to create a log file for the output of my commands inside a certain directory.Here is my code:mkdir "LogFiles\"@echo\ PING www.google.com^^ > LogFiles\command.log@echo\ IPCONFIG /ALL^^ >> LogFiles\command.log but this doesn't work. Could you please help me on this? Link to comment Share on other sites More sharing options...
jaclaz Posted November 12, 2014 Share Posted November 12, 2014 (edited) I would like to create a log file for the output of my commands inside a certain directory.Here is my code:mkdir "LogFiles\"@echo\ PING www.google.com^^ > LogFiles\command.log@echo\ IPCONFIG /ALL^^ >> LogFiles\command.log but this doesn't work. Could you please help me on this? Why are you using ^^ before redirection symbols?Wouldn't you want to make sure that you do not overwrite an existing "command.log"?What is that you want to accomplish, i.e. what do you actually want to have written to the "command.log" file?Are you sure you want to use "relative" paths such as the ones you used?WHAT (EXACTLY) does not work? Apart from the above, maybe what you really want/need is a "TEE" command. http://code.google.com/p/wintee/http://code.google.com/p/wintee/wiki/FAQ See if this:http://www.robvanderwoude.com/battech_redirection.phphelps you. The code you posted works fine, in the sense that it produces:a logfiles directory a command.log file in it with contents:PING www.google.com^IPCONFIG /ALL^Is this not what you expected? jaclaz Edited November 12, 2014 by jaclaz Link to comment Share on other sites More sharing options...
MHz Posted November 12, 2014 Share Posted November 12, 2014 Perhaps if your open to suggestion about the logging format, then perhaps the structure of a database might be better for saving multiple amounts of data. The example I show is using a 3rd party database tool known as SQLite and is used for local file based databases for applications and scripts. If you do not know SQL, then perhaps it may give you a reason to learn something new. This script executes the commands, saves the data to a sql file and then it is read in by sqlite3.exe to be inserted into the database. It will then display you some results by accessing the database. 1 table named logs with 2 columns named name and data. Both columns are set as type text.@echo offsetlocal enabledelayedexpansion@set prompt=::$G$S:: Just for clean, repetitive testing. Can be removed.if exist logs.db del logs.db:: Require::: sqlite-shell-win32-x86-3080701.zip (version number changes. File inside zip is sqlite3.exe):: download from http://www.sqlite.org/download.html:: Create the database if not exist and create the logs table.if not exist logs.db ( sqlite3 logs.db "create table logs (name TEXT, data TEXT);"):: Add begin transaction.echo begin;> tmp.sql:: Add insert values. Use 0 for 3rd parameter to not execute the 2nd parameter.call :addValues "TestName1" "echo Hello World"call :addValues "TestName2" "Hello Sun" "0"call :addValues "DirOutput" "dir /b"call :addValues "PingGoogle" "ping www.google.com"call :addValues "IPConfigAll" "ipconfig /all":: Add commit transaction.echo commit;>> tmp.sql:: Read the sql transaction file into the database.if exist logs.db if exist tmp.sql ( sqlite3 -cmd ".read tmp.sql" logs.db ""):::: Test database access.if exist logs.db ( :: Display data value of TestName1 from logs.db and store in a variable. echo 1. Select data from logs where name = 'TestName1'; for /f "usebackq delims=" %%A in ( `sqlite3 logs.db "select data from logs where name = 'TestName1';"` ) do set "data=%%A" echo !data! echo. :: Display all values of TestName2 from logs.db. echo 2. Select * from logs where name = 'TestName2'; sqlite3 -cmd ".mode line" logs.db "select * from logs where name = 'TestName2';" pause :: Display all values from logs.db. echo 3. Select * from logs; sqlite3 -cmd ".mode line" logs.db "select * from logs;" pause)endlocalgoto :eof:addValues setlocal enabledelayedexpansion :: 1st value. Idea of echo without newline from http://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line set "line=%~1" set "reply=" @echo | set /p "reply=insert into logs values ^('!line:'=''!','">> tmp.sql :: 2nd value. Executes the command and echos each line to a sql file. set "line=" if /i "%~3" == "0" ( :: Just the text with no newline. echo | set /p "reply=%~2">> tmp.sql ) else ( :: Execute and echo the output. for /f "delims=" %%A in ('%~2') do @( set "line=%%A" set "line=!line:'=''!" echo !line! ) ) >> tmp.sql echo '^);>> tmp.sql endlocalgoto :eofI will show only the output of the 1st 2 display outputs as the 3rd which displays all values is long, due to IPConfig /all etc.1. Select data from logs where name = 'TestName1';Hello World2. Select * from logs where name = 'TestName2'; name = TestName2 data = Hello SunEnsure sqlite3.exe in the current directory or %path% to test. Link to comment Share on other sites More sharing options...
jaclaz Posted November 12, 2014 Share Posted November 12, 2014 @MHz Should you by any chance need a torch/pocket light, have a look a this one: http://www.hexbright.com/ http://blog.amber.org/post/64781966869/overengineering-a-flashlight jaclaz Link to comment Share on other sites More sharing options...
MHz Posted November 13, 2014 Share Posted November 13, 2014 Thanks jaclaz. It is probably a good torch. I probably need some good eyes rather then a good torch. The price tag is probably bumped up a bit high for my liking. Makes me think of a keyboard in comparison with complexity. Many factors determine what I may buy and what I will not. As for my code, I am just getting started . Its 100% free so someone can take it or leave it. For an limited time, I will offer 50% off. Thats right, a huge 50% off. Get it while it lasts . Link to comment Share on other sites More sharing options...
jaclaz Posted November 13, 2014 Share Posted November 13, 2014 As for my code, I am just getting started . Its 100% free so someone can take it or leave it. For an limited time, I will offer 50% off. Thats right, a huge 50% off. Get it while it lasts . No special discount for resellers? jaclaz Link to comment Share on other sites More sharing options...
xtremee Posted November 18, 2014 Author Share Posted November 18, 2014 Thanks guys. This is really helped me a lot Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now