Here is the situation. We have a very old COBOL exe that will only run on Windows XP. In order to run this exe we have set up a virtual XP machine. Each week the user runs a series of BAT files.
I'm trying to write a C# Windows app that will run on the VM and then execute the COBOL exe. The plan is to use Process.Start to call the EXE. Everything works fine IF MY WINDOWS C# EXE runs in the same directory as the COBOL exe.
When I move the C# exe out of the folder, I get a bad return code and the cobol does not get executed.
Without going into a lot of detail, I want to be able to run the COBOL from outside of the folder. The reason is that we have several regional offices and each one has its own folder and its own copy of the cobol exe inside of each folder. The goal here is to let the user pick each regional office and then the C# program will execute each program in each directory.
In summary. If I run C# inside the folder where the COBOL exe lives, IT WORKS. BUT if I move C# outside of that folder it DOES NOT
I hope all this makes sense. Here are some additional details:
- Created in Visual Studio 2012 as a C# Windows Application
- Platform target x86 (I've also used Any CPU)
- Target framework .NET Framework 4
- COBOL is Microfocus from 1997 (yes I know. We need to get rid of it)
- VM is Windows XP
- If I change the exe to Notepad it runs fine
If I do start run from windows and paste this: K:\AMSapp\MYTESTFOLDER\AMSBLD.exe it runs fine.
C# code for button click event (note: if I change the filename to this K:\AMSapp\MYTESTFOLDER\AMSBLD.exe i get the same results. It does not run ) Also the message box is showing 255 for a return code when it does not work. If the C# program is moved inside of the cobol folder it returns a zero.
private void button1_Click(object sender, EventArgs e) { try { int exitCode; Process process = new Process(); process.StartInfo.FileName = @"\\SERVER23021\PRODDATA\AMSapp\MYTESTFOLDER\AMSBLD.exe"; process.StartInfo.ErrorDialog = true; process.Start(); process.WaitForExit(1000 * 60 * 5); // Wait up to five minutes. exitCode = process.ExitCode; MessageBox.Show("My exit code = " + exitCode.ToString()); MessageBox.Show("my path and file name: " + process.StartInfo.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); } }