I am trying to call a command prompt from a C# application and then the command prompt will run an argument to generate a nsis installer.
So this is the function inside the C# application which generate the installer:
private bool GenerateInstaller(string pStrVersion)
{
bool IsSuccess = false;
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
System.Diagnostics.Debug.WriteLine("Installer version: " + pStrVersion);
if(pStrVersion == "PRO")
{
startInfo.Arguments = @"""C:\Program Files (x86)\NSIS\makensis.exe"" ""Z:\Project\BuildArea\workspace\installer\Setup_PRO.nsi""";
System.Diagnostics.Debug.WriteLine("argument: " + startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
IsSuccess = true;
}
else
{
startInfo.Arguments = @"""C:\Program Files (x86)\NSIS\makensis.exe"" ""Z:\Project\BuildArea\workspace\installer\Setup_STD.nsi""";
System.Diagnostics.Debug.WriteLine("argument: " + startInfo.Arguments);
process.StartInfo = startInfo;
process.Start();
IsSuccess = true;
}
return IsSuccess;
}
The problem is when I try to run the C# app, it doesn't generate the installer. At the first time, I thought the string argument is wrong. So, I opened a new command prompt and try to run the argument directly and it works.
Do you have any idea what's wrong with my code?
Why don't you start makensis.exe directly?
startInfo.FileName = @"C:\Program Files (x86)\NSIS\makensis.exe";
startInfo.Arguments = @"Z:\Project\BuildArea\workspace\installer\Setup_PRO.nsi";
process.StartInfo = startInfo;
process.Start();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.