Hi: Thanks to all who read and help :)
I have an algorithm that is churning out a bunch of factors that I need to manage. Currently it is a simple cout that when running merely scrolls on the console page. Obviously it is impossible to capture the numbers because of the scroll. So I would like to have a more manageable output.
The code looks like this:
if (fabs(firstX - secondX) < fabs(0.05 * firstX) && fabs(firstY - secondY) < fabs(0.05 * firstY)) {
cout << firstX << ' / ' << firstY << endl;
cout << 'X factors: ' << array1[x1] << ' ' << array1[x2] << endl;
cout << 'Y factors: ' << array2[y1] << ' ' << array2[y2] << endl;
If this could be outputted to a file that I could open that would satisfactory. Could that be Notepad or could a spreadsheet like Excel or Microsoft Works Spreadsheet be used?
Or could the console window just hold the values such as in a table? Could you sort the information based upon the numerical value?
Currently the output (format) looks like:
937 / 785
X factors: 3.04, 0.43
Y factors: 0.32, 3.04
Thanks again!
I have an algorithm that is churning out a bunch of factors that I need to manage. Currently it is a simple cout that when running merely scrolls on the console page. Obviously it is impossible to capture the numbers because of the scroll. So I would like to have a more manageable output.
The code looks like this:
if (fabs(firstX - secondX) < fabs(0.05 * firstX) && fabs(firstY - secondY) < fabs(0.05 * firstY)) {
cout << firstX << ' / ' << firstY << endl;
cout << 'X factors: ' << array1[x1] << ' ' << array1[x2] << endl;
cout << 'Y factors: ' << array2[y1] << ' ' << array2[y2] << endl;
If this could be outputted to a file that I could open that would satisfactory. Could that be Notepad or could a spreadsheet like Excel or Microsoft Works Spreadsheet be used?
Or could the console window just hold the values such as in a table? Could you sort the information based upon the numerical value?
Currently the output (format) looks like:
937 / 785
X factors: 3.04, 0.43
Y factors: 0.32, 3.04
Thanks again!
Similarly, there is output redirection:% a.out outputfile. That allows us to use cout as before, but that causes the output of the program to go to a file (e.g., outputfile above) instead of the screen. Of course, the 2 types of redirection can be used at the same time.% a.out outputfile. If you're running the program from the command line, simply redirect the output to a pager or a file. Yourapp less or yourapp out.txt 2. You can write directly to a file yourself. You need to create file and write to the file instead of cout. At the top of your program add.
-->Definition
Gets or sets a value that indicates whether the textual output of an application is written to the StandardOutput stream.
Property Value
true
if output should be written to StandardOutput; otherwise, false
. The default is false
.Examples
Remarks
When a Process writes text to its standard stream, that text is typically displayed on the console. By setting RedirectStandardOutput to
true
to redirect the StandardOutput stream, you can manipulate or suppress the output of a process. For example, you can filter the text, format it differently, or write the output to both the console and a designated log file.Note
You must set UseShellExecute to
false
if you want to set RedirectStandardOutput to true
. Otherwise, reading from the StandardOutput stream throws an exception.The redirected StandardOutput stream can be read synchronously or asynchronously. Methods such as Read, ReadLine, and ReadToEnd perform synchronous read operations on the output stream of the process. These synchronous read operations do not complete until the associated Process writes to its StandardOutput stream, or closes the stream.
In contrast, BeginOutputReadLine starts asynchronous read operations on the StandardOutput stream. This method enables a designated event handler (see OutputDataReceived) for the stream output and immediately returns to the caller, which can perform other work while the stream output is directed to the event handler.
Note
The application that is processing the asynchronous output should call the WaitForExit method to ensure that the output buffer has been flushed.
Synchronous read operations introduce a dependency between the caller reading from the StandardOutput stream and the child process writing to that stream. These dependencies can cause deadlock conditions. When the caller reads from the redirected stream of a child process, it is dependent on the child. The caller waits for the read operation until the child writes to the stream or closes the stream. When the child process writes enough data to fill its redirected stream, it is dependent on the parent. The child process waits for the next write operation until the parent reads from the full stream or closes the stream. The deadlock condition results when the caller and child process wait for each other to complete an operation, and neither can continue. You can avoid deadlocks by evaluating dependencies between the caller and child process.
The last two examples in this section use the Start method to launch an executable named Write500Lines.exe. The following example contains its source code.
The following example shows how to read from a redirected stream and wait for the child process to exit. The example avoids a deadlock condition by calling
p.StandardOutput.ReadToEnd
before p.WaitForExit
. A deadlock condition can result if the parent process calls p.WaitForExit
before p.StandardOutput.ReadToEnd
and the child process writes enough text to fill the redirected stream. The parent process would wait indefinitely for the child process to exit. The child process would wait indefinitely for the parent to read from the full StandardOutput stream.There is a similar issue when you read all text from both the standard output and standard error streams. The following example performs a read operation on both streams. It avoids the deadlock condition by performing asynchronous read operations on the StandardError stream. A deadlock condition results if the parent process calls
p.StandardOutput.ReadToEnd
followed by p.StandardError.ReadToEnd
and the child process writes enough text to fill its error stream. The parent process would wait indefinitely for the child process to close its StandardOutput stream. The child process would wait indefinitely for the parent to read from the full StandardError stream.You can use asynchronous read operations to avoid these dependencies and their deadlock potential. Alternately, you can avoid the deadlock condition by creating two threads and reading the output of each stream on a separate thread.