Calling console application from asp.net

2019-03-21 11:30发布

问题:

I try to call console appliction from asp.net when i put breakpoint in console app why it can't stop there.How can i call console application?

 var proc = Process.Start("D:\\Edefter\\EFaturaConsoleTxtParser\\bin\\Debug\\EFaturaConsoleTxtParser.exe", "/arg1 /arg2");
                proc.WaitForExit();

回答1:

I'm not sure about this but anyway you can try

  ProcessStartInfo startinfo = new ProcessStartInfo();   
    startinfo.FileName =@"D:\\Edefter\\EFaturaConsoleTxtParser\\bin\\Debug\\EFaturaConsoleTxtParser.exe";   
    startinfo.CreateNoWindow = true;   
    startinfo.UseShellExecute = true; 
    Process myProcess = Process.Start(startinfo);
    myProcess.Start();


回答2:

While starting a process programmatically, the 'UserShellExcute' property must be 'false'. Otherwise, the CreateNoWindow property value gets ignored and new window is created.

Example:

 ProcessStartInfo startinfo = new ProcessStartInfo();
 startinfo.FileName = @"demoApplication.exe";
 startinfo.Arguments = "arg1 arg2";
 startinfo.CreateNoWindow = true;
 startinfo.UseShellExecute = false;
 Process myProcess = Process.Start(startinfo);

Source: http://msdn.microsoft.com