Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey!
I have a problem with my C' Program.
My program is some kind of C Online Compiler. It reads a source file, compiles it and then runs the file and the user should be able to give the Program an input.

The compiling part works. But when I start the executable file through code it skips all the inputs the program asks for.

My Program runs on a Linux VM.

My code:

    private void StartProgramRun()
        {
            try
            {
                _currentProgram = new Process();
                _currentProgram.StartInfo.FileName = $"mypath";
                _currentProgram.StartInfo.RedirectStandardInput = true;
                _currentProgram.StartInfo.RedirectStandardOutput = true;
                _currentProgram.StartInfo.RedirectStandardError = true;
                _currentProgram.StartInfo.UseShellExecute = false;
                _currentProgram.EnableRaisingEvents = true;

                _currentProgram.Exited += CurrentProgram_Exited;
                _currentProgram.OutputDataReceived += CurrentProgram_OutputDataReceived;
                _currentProgram.ErrorDataReceived += CurrentProgram_OutputDataReceived;

                _currentProgram.Start();

                _currentProgram.BeginOutputReadLine();
                _currentProgram.BeginErrorReadLine();
            }
            catch (Exception ex)
            {
                _currentChannel.SendMessageAsync("Error on ProcessStart: " + ex.Message);
            }
        }

        private void CurrentProgram_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.Data))
            {
                //displays the message to the user
            }
        }

private void CurrentProgram_Exited(object sender, EventArgs e)
        {
            //displays that the program exited and deletes the executable

            File.Delete($"mypath");
        }


_currentProgram is a global variable.
"mypath" is the path to the executable file.

What I have tried:

I tried to execute the file via '/bin/bash' and I tried to execute the executable itself.
Posted
Updated 5-Dec-20 17:59pm
v3
Comments
[no name] 4-Dec-20 8:53am    
$"mypath" is a literal; same as "mypath". That's it. If you think it resolves to something else, you're mistaken.

1 solution

Gerry Schmitz[^] is correct. You will need to change "mypath" to the actual path of the executable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900