Hello, I'm using a process to compile java source code from within my program. I am then attempting to read the output ( errors , if it compiled ok etc) . But for some reason it isn't working. It works fine when using other shell commands ( ping etc ) but no output is displayed with javac.

Process process = new Process();

                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.FileName = "javac.exe";
                process.StartInfo.Arguments = "source.java";

                process.Start();

                MessageBox.Show(process.StandardOutput.ReadToEnd()); // for testing

Any suggestions?


: Edit problem solved was using standardoutput instead of error =/

Hi,

I have a similar problem. I try to run a Program and I want to see its output in a RichTextBox.

void start_process(){
    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = "path/to/*.exe";
    psi.WorkingDirectory = "path/to/working_directory";
    psi.UseShellExecute = false;                    
    psi.RedirectStandardOutput = true;         

    Process myProc = Process.Start(psi);      

    myProc.OutputDataReceived += new DataReceivedEventHandler(myProc_OutputDataReceived);
        // this is a suggestion of MS Visual C# Studio 2005 ^^
}

void myProc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    RichTextBox1.AppendText(e.Data+"\n");
}

Thanks!

opatut

Hi,

I have a similar problem. I try to run a Program and I want to see its output in a RichTextBox.

void start_process(){
    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = "path/to/*.exe";
    psi.WorkingDirectory = "path/to/working_directory";
    psi.UseShellExecute = false;                    
    psi.RedirectStandardOutput = true;         

    Process myProc = Process.Start(psi);      

    myProc.OutputDataReceived += new DataReceivedEventHandler(myProc_OutputDataReceived);
        // this is a suggestion of MS Visual C# Studio 2005 ^^
}

void myProc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
    RichTextBox1.AppendText(e.Data+"\n");
}

Thanks!

opatut

// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();


From MSDN Library.

// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();


From MSDN Library.

// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();


From MSDN Library.

Thanks royael. Problems is solved. Its succesfull...

commented: Don't bump old threads -1

I'm glad you got it helpful. Please do not resurrect old threads. If you have any questions please ask. .... You are welcome to start your own threads.

Please read the rules before posting again - http://www.daniweb.com/forums/thread78223.html and rules.

Thread Closed.

commented: you seem to have a patience of a saint to keep closing dozen of "Grand returns" and remain same unflappable :D +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.