Advertisement

03.20.2008 at 11:45PM PDT, ID: 23259210
[x]
Attachment Details

Running external application through cmd from C# code

Asked by snowalps in Microsoft Visual C#.Net

hi,

iam trying to open up an excel sheet from a batch file using my c# code. I did this by opening the command prompt and reading the batch file contents and writing on the cmd window to execute it. Now when i separately run the batch file, it opens up the excel sheet, so the bat file is correct.But when i do this from my code, the excle sheet does not open, but i can see EXCEL.EXE being run by aspnet in my taskmanager. why cant i see the excel opening up after i run my code?
here is the code iam using:

try
                  {

                        ProcessStartInfo psi = new ProcessStartInfo("cmd.exe");
                        psi.UseShellExecute = false;
                        psi.RedirectStandardOutput = true;
                        psi.RedirectStandardInput = true;
                        psi.RedirectStandardError = true;
                        psi.WorkingDirectory = @"C:\TEST\";

                        // Start the process
                        Process proc = Process.Start(psi);
                              
                        StreamReader strm = File.OpenText(@"c:\TEST\new.bat");
                        // Attach the output for reading
                        StreamReader sOut = proc.StandardOutput;
                        // Attach the in for writing
                        StreamWriter sIn = proc.StandardInput;
                        // Write each line of the batch file to standard input
                        while(strm.Peek() != -1)
                        {
                              sIn.WriteLine(strm.ReadLine());
                        }
                        sIn.WriteLine("EXIT");
                        proc.Close();
                  }
                  catch (System.Exception ex)
                  {
                        Console.WriteLine (ex.Message);
                  }


when i debug the code, it does not go to the catch block which means it is not encountering any error, but still the excel does not seem to open! the task manager though shows that excel.exe was triggered  by aspnet.
pls suggest what can be wrong. i need this very urgently..
thanks in advance.Start Free Trial
[+][-]03.20.2008 at 11:48PM PDT, ID: 21178507

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 11:54PM PDT, ID: 21178521

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 11:59PM PDT, ID: 21178527

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.21.2008 at 12:05AM PDT, ID: 21178539

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.21.2008 at 12:28AM PDT, ID: 21178579

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.21.2008 at 12:32AM PDT, ID: 21178590

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.21.2008 at 02:31AM PDT, ID: 21178817

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 03:16AM PDT, ID: 21332693

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual C#.Net
Sign Up Now!
Solution Provided By: snowalps
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628