Execute command with windows command line and capture output in rolling file - windows

I have a command line program that produces output that I would like to log to a file.
I know that I can redirect the output of a command (foo.exe for example) to a file using the > operator, but for this current project I need more than just simple output functionality. I would also mention that I can't change any of the code in foo.exe.
I am looking for a command line utility/command that can do the following:
Log the output of a foo.exe to a file
Place a timestamp on each individual output of foo.exe
When the current log file reaches a certain specified size (say 1mb), close the current file and start putting log data in a new file.
In a perfect world the utility would encapsulate the command I wish to execute and log its output, looking something like the following:
log.exe -MaxLogSize=1mb -FileName="FooOutput.log" -Execute="foo.exe"
Any help or suggestions are appreciated!

Related

Command line command order

Today I wanted to get a list of files in a particular directory. The easiest way to accomplish this is to open a prompt and run a
dir > filelist.txt
I assumed that first the 'dir' command runs and then its output is created. It is THEN redirected to the file.
What is interesting however is that the directory listing inside of 'filelist.txt' includes 'fielist.txt' with zero bytes which was not expected.
Once the command completes 'filelist.txt' actually shows as having 450 bytes (when I run a dir without the redirection, same prompt).
1) Why does 'filelist'txt' show up at all?
2) What is the command prompt doing behind the scenes?
I assumed that first the 'dir' command runs and then its output is created.
Where would the output live in the meantime?
The output is by default displayed on the console, almost immediately after being output by the program.
Now if you redirect the output to a file instead, it is written to that file as it would be written to the console: at the moment the program writes the output.
Even when a command has no output, the file is still created. The console first tries to create the requested output file; if that fails, the requested command won't even be executed.

Using redirects inside a batch file

This seems like I'm missing something obvious but I can't get redirects (>) to work in a .bat / .cmd file.
From the command line, this works as expected and sends the output and error streams to the log file:
doxygen doxygen.config 2>&1 > doxygen.log
Putting the exact same line inside a batch file and running it doesn't work however. It looks like it tries to write the entire command to the log file rather than execute it and then loops??
How do I get output redirects to work inside a bat / cmd file? In case it makes a difference, I am using Win7 and have tried from cmd and powershell.
Perhaps the batch script is calling itself. I would suggest you explicitly specify the extension for the executable your script is calling:
doxygen.exe doxygen.config 2>&1 > doxygen.log

How do I Pipe Standard Error to a File in DOS (Batch File)?

How do I pipe standard error to a file in a DOS batch file? Piping using >> only pipes the standard output and the standard error still goes to the console.
Details of my issue:
I am running WinRAR via command line, in an automated daily backup. And the following example pipes WinRar's output, but not the error output which is what I want most, to winraroutput.txt:
RAR.exe a -esh -r "E:\backup.rar" "D:\*.*" >> winraroutput.txt
The issue is sometimes files are in use and when they are I want to know they were missed in the archive and record this in a .txt file next to each .rar file in case we ever have to go back. The missing files are easily replaced by reinstalling programs so it's no big deal to replace them, as long as we know they are missing. So it's just information that would be great to know, not necessary, in the time of need.
How do I output just the standard error output to the .txt file and, if possible but not necessary, leave the the regular output to the console?
Bonus points:
Bonus points if you can tell me how to delete the file if it's blank (no errors)! Asked here: How do I Detect (and Delete) a File if it is Empty using a Windows Batch File?.
Try this:
command.exe 2>file.txt
Or if you prefer not to see any errors, send it to nul:
command.exe 2>nul
This should leave std::cout on the console.

Windows .bat file doesn't execute its sequence

I created a simple install.bat file into my application folder, to execute its thing on windows.
But it only executes the first line of the .bat file.
Is there something that I need to add so it continues after the first one is done?
copy something somewhere
move something somewhereelse
gem install etc
Above are the type of commands that are in the .bat.
Do I need to anything something inbetween?
Is the first command in your batch file actually a copy command, or is it a command that's running another batch file?
Running a batch file from another by simply using the second batch file;s name will not return to the calling batch file.
If you want one batch file to invoke another and return you have to use the call command.
Are you overwriting a file? If so you'll need to add the /Y to the copy command to supress the prompt that asks if you want to overwrite the file.
Use the /h parameter to get help on the copy command. It will show this usage and some others.
As written above, all three lines will execute. I imagine that the second and third lines are failing. You should capture the output which will explain why those lines failed.

how to debug VC++ program, input file not open while debuging

i am using Visual studio 8. i pass command line argument to my program when i execute the program using exe file it works fine but when i use to debugg. it is unable to open the input file which i have given it in the form of command line argument. although i have given the command line argument in the Project->properties->debug->command line arguments....
e.g
"program.exe" input_file output_file
input file contains data which i have to use in the calculation if i am unable to debug it. how can i remove the errors in my program
reply me
thanks
You may need to specify the working directory on that same property page in order to have your debug executable run in the same directory as your input file. Right now it's probably not able to pass your file because it can't find it.
You should not include "program.exe" in the command line arguments.

Resources