Link to home
Start Free TrialLog in
Avatar of Frank Bryant
Frank BryantFlag for United States of America

asked on

Open a Text Editor from the Command Line Programatically using C#

First let me say that I am a novice when it comes to C#; I am using Visual Studio Enterprise 2015.

I am trying to run a Macro from a Text Editor (Ultraedit) using the Command Line Shell in C# programmatically and I have not been successful.

Here is the text editor Command Line ... uedit32 /fni DriveLetter:\Path\TextFileName.txt /m="DriveLetter:\Path\MacroName.mac" ... I know it works as I ran it from a (Start --> Run) Command Window to test it.

Anyway, here is the problem that I am trying to solve; I have a VERY Large text file which has errors that have to be resolved before it can be imported. This one file is to large to run macros on (out of memory error),  so I have an ultraedit script that takes this very large text file and splits it into several smaller files at 175,000 rows each. I currently have 28 smaller files and four macros to run; 4 x 28 = 112 iterations. I want to automate this process; can it be done?

For what it is worth, here is the C# Code that I am using ...

            // There are 28 Separate Text Files each with 175,000 Data Rows to Be Modified ...
            for (int TheTextFileToBeRead_Loop = 1; TheTextFileToBeRead_Loop <= 28; TheTextFileToBeRead_Loop++)
            {
                for (int TheMacroToBeExecuted_Loop = 0; TheMacroToBeExecuted_Loop <= 3; TheMacroToBeExecuted_Loop++)
                {
                    CmdLineToExecute = @"uedit32 /fni DriveLetter:\Path\TextFileName" + TheTextFileToBeRead_Loop  + ".txt /m=" + (char)34 + @"DriveLetter:\Path\MacroName" + TheMacroToBeExecuted_Loop + ".mac" + (char)34;
                    System.Diagnostics.Process.Start("CMD.exe", CmdLineToExecute);
                }
            }
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Frank Bryant

ASKER

Bingo! :)
Here is the correct code ...

                    CmdLineToExecute = @"C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\Uedit32.exe"
                    TheArgumentsToPassAre = " /fni DriveLetter:\Path\TextFileName" + TheTextFileToBeRead_Loop  + ".txt /m,e=" + (char)34 + @"DriveLetter:\Path\MacroName" + TheMacroToBeExecuted_Loop + ".mac" + (char)34;

                    System.Diagnostics.Process.Start(TheCommandLineToExecuteIs, TheArgumentsToPassAre);