0

I have a C++ program (Test.exe) that takes in a number N (passed as command line argument) and generates coordinates for N rectangles written to a text file.

I have tested this via the command line and in Visual Studio, and on both occasions the file is written with the expected output.

In a C# program I enter N in a textbox, click a button and my event code is as follows:

Process p = new Process();
p.StartInfo.FileName = "Test.exe";
p.StartInfo.Arguments = num;
p.Start();
// read the file that Test.exe created

A file is not written by Test.exe.

Any suggestions as to why Test.exe doesn't write the file when it is called from the C# program?

Problem Found The file was being written in the directory where the C# program was executed from NOT from where the C++ program was located.

2 Answers 2

2

I guess you forgot p.WaitForExit() right after the p.Start() line.

Sign up to request clarification or add additional context in comments.

2 Comments

StartInfo.WorkingDirectory would be an excellent candidate as well. The default is rarely writable.
Even with using p.WaitForExit(), the file is not written
2

Two points:

  1. Make sure the working directory of Test.exe (StartInfo.WorkingDirectory) is set to a directory where the process has write access, and
  2. If Test.exe needs process elevation, use StartInfo.UseShellExecute = true and StartInfo.Verb = "runas" to start an elevated process. Your C# program needs to be an elevated process to do this, you can use an application manifest file for this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.