Reputation: 159
I have made an application in Visual C++ (That uses the command line). I have made a GUI for the same in Visual C# so that the user will not have to use the command line and can run it from the GUI. Now, how do I go about making an installer for the same? In my GUI I have the following code that calls my application and runs it:
string cmdText;
cmdText = @"C++HeaderConversionToQFASTXML.exe " + " " + textBox1.Text + " " + textBox2.Text;
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.CreateNoWindow = true;
info.WorkingDirectory = @"C:\forAbishek\C++HeaderConversionToQFASTXML\Release\";
Process p = Process.Start(info);
p.StandardInput.WriteLine(cmdText);
In this I want the working directory to be the directory where the .exe (C++HeaderConversionToQFASTXML.exe) will reside in the users machine. How do I ensure that the GUI picks up this? The .exe will be installed on the users machine. Can someone help me out? Thank you.
I have made the following change:
string cmdText;
cmdText = @"C++HeaderConversionToQFASTXML.exe " + " " + textBox1.Text + " " + textBox2.Text;
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.CreateNoWindow = true;
String path = System.Reflection.Assembly.GetExecutingAssembly().Location;
path = System.IO.Path.GetDirectoryName(path);
Directory.SetCurrentDirectory(path);
MessageBox.Show(path);
info.WorkingDirectory = path;
Process p = Process.Start(info);
p.StandardInput.WriteLine(cmdText);
It still isn't working. Where am I going wrong?
Upvotes: 0
Views: 155
Reputation: 6061
Unless there is a reason you can't do so, I'd suggest configuring the installer to put the CLI and GUI executables in the same location and skip the whole relative path issue entirely.
If you want to allow the user to create non-default post-install configurations where the apps are in different locations, add an app.info file for your C# app where the user can specify the location of the CLI app if it's not in the same folder as the UI.
I'm not aware of any easy way to specify two different locations in an installer and use them to dynamically create/modify an app.info file. If you need that I think you'll need to write a custom config app that's called by the installer to create the app.info file.
Upvotes: 1