Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOS command redirect to file truncates output

I have a command line tool that typically dumps out about 200+ lines of output. I'm looking for text that appears at the end of this output. When I redirect the output to a file:

C:\> somecommand > results.txt 2>&1

...only the first 100 or so lines of output shows up in this file. Likewise, if I pipe the output into something like 'findstr', the receiving program is unable to find or operate on any text after about the 100th line.

The screen buffer size settings for the shell appear to have no effect whatsoever on the number of lines that can be captured.

Any ideas what is going on here? For what it's worth, the command in question is iscmdbld.exe from InstallShield 2012.

This problem does not occur with other commands I've tried (such as 'dir').

The full output from the program can only be viewed when running the command within a cmd window.

like image 946
Hoobajoob Avatar asked Jul 20 '12 21:07

Hoobajoob


2 Answers

Well unfortunately I do not have InstallShield installed so it will be quite hard for me to run some test, but I have cam across programs that are not acting as they supposed to do when it comes to handling input and output. In a normal case ">" should have NO limit, I'm using it a lot on a windows server which is running ghostscript and other old dos programs in the background and the only way to pipe the output to a file is to use >, sometimes I have files of quite a few Mb, so the 200 lines really has to do something with the current exe.

I can only suggest to try some workaround, for example you can try tee32, it's a small freeware which will capture all the dos screen output to a file. So you will see the output on the screen and you will have it in file too.

You can read more about it: here unfortunately the links mentioned on the page are not working, but I was able to find a working copy of it: here

I really hope this will help you overcome the problem.

Emil

like image 179
Emil Borconi Avatar answered Oct 18 '22 03:10

Emil Borconi


An alternative solution to your problem might be building an C# program that captures the output and sends it to a file.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CaptureCMDOutput
{
    class Program
    {
        static string _Filename = @"sc.exe";
        static string _Arguments = @"query";
        static string _outputfile = @"c:\debug.txt";

        static void Main(string[] args)
        {
            var processStartInfo = new ProcessStartInfo
            {
                FileName = _Filename, // Exe file to run
                Arguments = _Arguments, // Arguments to exe file
                RedirectStandardOutput = true,
                UseShellExecute = false
            };

            var process = Process.Start(processStartInfo);
            process.OutputDataReceived += process_OutputDataReceived;
            process.BeginOutputReadLine();
            process.WaitForExit();
            process.CancelOutputRead();

            Console.ReadKey();
        }

        static void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            Console.WriteLine(e.Data);

            using (StreamWriter writer = new StreamWriter(_outputfile, true))
            {
                writer.WriteLine(e.Data);
            }
        }


    }
}
like image 2
Daniel Björk Avatar answered Oct 18 '22 02:10

Daniel Björk