naval Parekh
naval Parekh

Reputation: 51

Dos create a batch file and run with multiple C++ programs

Respected sirs,

My name is @nimit. I want to create a batch file and run it in a DOS prompt. The batch file will execute a C++ program I've written. The output should be stored in a single text-file. How can I do this?

The C++ program output should be stored in a particular text file.

Thanks in advance, @nimit

Upvotes: 2

Views: 982

Answers (3)

Phong
Phong

Reputation: 6768

The following will redirect program output (stdout) to a file (overwrite file or create it if it does not exist)

$ command-name > output.log

The following will redirect program output (stdout) to a file (append file or create it if it does not exist)

$ command-name >> output.log
$ command-name >> output.log

The following will redirect program error message to a file called error.log:

$ command-name 2> error.log

Redirecting the standard error (stderr) and stdout to file, Use the following syntax:

$ command-name &> output_error.log

Upvotes: 0

misterich
misterich

Reputation: 93

Shell scripting (Batch files are a form of that) is something that every programmer should know how to do. I found a really great book on it a few years ago: Unix Shell Programming by Stephen Kochan and Patrick Wood. Granted, it's Unix -- and bash is far more powerful than DOS, but the principles are the same. Windows is picking up a lot of the tools that bash offers with powershell.

For a great website that lists out all of the CMD programs, visit http:// ss64.com/nt/ . That site also lists comparable bash and powershell commands. I also like how he shows you how to implement pseudo-functions, command line parameters, and all manner of cool things in batch files: http://ss64.com/nt/syntax.html

Good luck!

Upvotes: 0

GManNickG
GManNickG

Reputation: 503855

You can do this:

programname > outputgoeshere.txt

To collect outputs:

programname1 >> outputgoeshere.txt
programname2 >> outputgoeshere.txt
programname3 >> outputgoeshere.txt

Upvotes: 1

Related Questions