I have tried absolutely everything I can think of to execute an external legacy App I have through C#, but it just won't work properly unless I manually use the command prompt. So far, I have tried:
a) Executing the process directly:
// Path to Legacy App;
var procName = @"C:\Path to Exe\With lots of Spaces\In the name.exe";
//Happens to be a path to a text file
var arg1 = @"C:\Long Path Name\With Spaces to\Input File Name.txt";
//Legacy Exe uses this char to separate 'source' and 'target' text files.
var arg2 = " > ";
// Name of the new text file to create, once processed by procName
var arg3 = @"C:\Long Path Name\With Spaces to\Input File Name_new.txt";
Process.Start(procName, arg1 + arg2 + arg3); => FAILS
b) I tried calling cmd.exe and then feeding it the exe path and the args:
// Path to Legacy App
var arg1 = @"C:\Path to Exe\With lots of Spaces\In the name.exe";
//Happens to be a path to a text file
var arg2 = @"C:\Long Path Name\With Spaces to\Input File Name.txt";
//Legacy Exe uses this char to separate 'source' and 'target' text files.
var arg3 = " > ";
// Name of the new text file to create, once processed by procName
var arg4 = @"C:\Long Path Name\With Spaces to\Input File Name_new.txt";
var allArgs = arg1 + arg2 + arg3 + arg4;
Process.Start("cmd.exe", allArgs); => FAILS
I have tried everything I can think of, including adding /k, /s or both before calling the initial exe, wrapping everything in quotes, wrapping each argument in quotes, etc. I even used an 8.3 shortened path name for the path to the legacy exe since the command prompt would sometimes say it could not find the app and would stop at the first space.
Of course, if I open a command prompt and I copy-paste the contents of allArgs into cmd and execute, the external app runs properly and I get my modified text file.
If anyone has any pointers or suggestions I am happy to explore all avenues. I am at my wits end.
This should not be this hard.
Thank you!