Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:29:12+00:00 2026-06-06T21:29:12+00:00

this is my first question here so I’ll be as detailed as I can.

  • 0

this is my first question here so I’ll be as detailed as I can. I am currently working on a C# program (We’ll call it TestProgram) that tests a different program written in C (which I’ll refer to as StringGen). TestProgram is supposed to run StringGen in a command window, then feed it a set of input strings and record the output for each one. When StringGen is run, it starts a while loop which waits for an input, submits that input to the processing function, then returns the result.

My problem comes from when I try and have TestProgram submit a string to StringGen. I’m starting StringGen as a process and attempting to feed it input with Process.StandardInput.WriteLine(), then looking for output with Process.StandardOutput.ReadLine(). Before I elaborate further, I’ll supply some code.

Here is the main function for StringGen:

int main() {
    char result[255];
    char input[255];

    do {
        fgets(input, 100, stdin);
        result = GetDevices(input); //Returns the string required
        printf("%s", result);
    } while (input != "quit");

    return 0;
}

Here is the C# code where I define StringGen as a process:

Process cmd = new Process();

ProcessStartInfo info = new ProcessStartInfo(command, arguements); // Command is the path to the C executeable for StringGen
info.WorkingDirectory = workingDirectory; // Working Directory is the directory where Command is stored
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.UseShellExecute = false;
cmd.StartInfo = info;
cmd.Start();

Then I go on to use this process as so:

using (var cmd)
        {
            // Loop through the input strings
            String response;

            foreach (exampleString in StringSet) // Loops through each string
            {
                cmd.StandardInput.WriteLine(exampleString.text); // This is the problem line
                response = cmd.StandardOutput.ReadLine(); // System comes to a halt here
                cmd.StandardOutput.Close();
                if (response == "Something")
                {
                     // Do this
                }
                else
                {
                     // Do that
                }
            }
       }

The WriteLine command does not seem to give any input to StringGen, and so the system hangs at ReadLine because StringGen is not giving any output back. I’ve tried running StringGen at command line and it works fine and takes input from keyboard and outputs the correct strings back. I’ve tried everything I can think of and searched all over this site and others trying to find a solution but every example of this kind of code seems to be work fine for everyone else. I can’t see what I’m doing wrong. If anyone could suggest a way that I can submit input to my StringGen program from TestProgram I would be really grateful. If I have left anything important out or if anything is unclear, please let me know.

Notes:
I have tried both scanf and fgets in StringGen, both produce the same result.

I have tried using a literal string with WriteLine(), but still no input.

I have tried useing Write() and Flush() in TestProgram but to no avail.

I have tried to Close() the input buffer to force a flush, but this has no effect either.

I am not overly familiar with C# as I am editing someone elses code to perform tests on StringGen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:29:13+00:00Added an answer on June 6, 2026 at 9:29 pm

    I think the problem is in your C program, not in your C# program. When you produce your output, you do not put \n at the end. Hence StandardOutput.ReadLine() will wait forever, because there is no end-of-line marker in the stream.

    Since the output of your C program is used to synchronize the steps of your co-operating programs, it is also a very good idea to flush it to the output before waiting for the next portion of input:

    printf("%s\n", result);
    fflush(stdout);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question here. I have a notepad app that you can
this is my first question here :) I know that I should not check
Ok, I need help. This is my first question here. Background: I am working
This is my first question here, so I hope that I am providing enough
this my first question on here. I hope someone can help. It is to
This is my first question here on stackoverflow, so I hope that I am
this is my first question here so I hope I can articulate it well
Hello this is my first question here, I create a Web Service that is
this is my first question here so be gentle ! recently i try to
This is my first question here so try to make my best so you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.