Reading output from console through asp.net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Reading output from console through asp.net

  1. #1
    Join Date
    Aug 2014
    Posts
    2

    Reading output from console through asp.net

    I am using this code to pass two numbers as input to an .exe of a C program file through asp.net and after that trying to read the output from console. I am having problem to read any output from the console. My asp.net code is.
    Code:
    string returnvalue;
    
    Process p = new Process();
    
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    p.StartInfo.FileName = ("C:\\Users\\...\\noname01.exe");
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardInput = true;
    p.Start();
    Thread.Sleep(500);
    SendKeys.SendWait("1");
    Thread.Sleep(500);
    SendKeys.SendWait("~");
    Thread.Sleep(500);
    SendKeys.SendWait("2");
    Thread.Sleep(500);
    SendKeys.SendWait("~");
    Thread.Sleep(500);
    
    StreamReader sr = p.StandardOutput;
    
    returnvalue = sr.ReadToEnd();
    
    System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\...\\StudentOutput.txt");
    file.WriteLine(returnvalue);
    My C code to which am passing inputs is.
    Code:
    #include<stdio.h>
    
        int main()
        {
        int a, b, c;
    
        printf("Enter two numbers to add\n");
        scanf("%d%d",&a,&b);
    
        c = a + b;
    
        printf("Sum of entered numbers = %d\n",c);
    
        return 0;
        }

    I am having problem to read any output from the console.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,478

    Re: Reading output from console through asp.net

    Perhaps it's a permissions issue. Or it might be the account asp.net runs under can't access the console. Try piping the output of the exe to a file and then read the file.

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: Reading output from console through asp.net

    I am having problem to read any output from the console.
    What problems are you having?

    I don't see any error checking in your asp.net code?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Aug 2014
    Posts
    2

    Re: Reading output from console through asp.net

    Quote Originally Posted by 2kaud View Post
    I don't see any error checking in your asp.net code?
    Whenever i run my program it opens the .exe file of the C program and pass the in put through sendkeys
    now i want to read all of that output from the console of the C program but its not working

  5. #5
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: Reading output from console through asp.net

    Quote Originally Posted by hussainahmad007 View Post
    Whenever i run my program it opens the .exe file of the C program and pass the in put through sendkeys
    now i want to read all of that output from the console of the C program but its not working
    In what way is it not working? Do you get any errors reported?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,478

    Re: Reading output from console through asp.net

    Sorry to say, but using send keys with a console app isn't the most reliable approach even under the best circumstances.

    That being said, did you read my first response? Did that make sense?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center